Skip to content

Composite S/R loss, SEC filings pipeline, CVaR benchmark, and pyfolio visualization#74

Open
v-atharva wants to merge 3 commits intoatharva/feature_selectionfrom
atharva/mymodel
Open

Composite S/R loss, SEC filings pipeline, CVaR benchmark, and pyfolio visualization#74
v-atharva wants to merge 3 commits intoatharva/feature_selectionfrom
atharva/mymodel

Conversation

@v-atharva
Copy link
Copy Markdown
Collaborator

Summary

This PR extends financial_loss_functions with a multi-component training objective, optional SEC-derived fundamentals, a CVaR portfolio benchmark, and pyfolio-based strategy reporting. It is based on atharva/feature_selection.

Changes

Composite loss (CompositeSRLoss)

  • Sharpe (existing differentiable objective) plus four regularizers:
    • Price action: microstructure signals (turnover, illiquidity, BA spread, return smoothing) aligned with allocation vs. equal weight.
    • Psychological levels: cumulative return proximity to return-space thresholds.
    • Macro regime: learnable weights over broadcast macro features vs. forward portfolio return.
    • Fundamentals (optional): alignment with pre-computed SEC composite scores when composite_fundamental_scores.csv is present.

Training

  • Trainer passes (weights, y, x, fundamentals?) to the loss; legacy 2-arg losses still work.
  • pipeline.py trains BaseLSTM (Sharpe baseline), BaseLSTM + composite, AttentionLSTM + composite, runs CVaR benchmark, equal weight, and generates pyfolio tearsheets plus a CSV summary.

Data & tooling

  • SEC: src/data_collection/sec_filings.py and scripts/run_sec_collection.py (edgartools; cache under data/raw/sec_filings/).
  • CVaR: src/models/cvar_benchmark.py (CVXPY / CLARABEL, no GPU requirement).
  • pyfolio: src/evaluation/pyfolio_viz.py (pyfolio-reloaded).

Config & dependencies

  • config/hparams.json: CompositeSRLoss, CVaRBenchmark.
  • config/paths.json: sec_filings_dir, pyfolio_output.
  • requirements.txt: cvxpy, edgartools, pyfolio-reloaded, empyrical-reloaded.

Tests

  • tests/unit/test_composite_loss.py, test_cvar_benchmark.py, test_sec_filings.py, test_pyfolio_viz.py.

Other

  • Updates exploration/feature_selection_findings.ipynb as part of the working tree.

How to verify

cd financial_loss_functions
pip install -r requirements.txt
pytest tests/unit/test_composite_loss.py tests/unit/test_cvar_benchmark.py tests/unit/test_sec_filings.py tests/unit/test_pyfolio_viz.py -v

Notes

  • SEC collection requires network access and a valid EDGAR_IDENTITY / set_identity for edgartools; training runs without SEC data (fundamental term skipped).
  • cvxpy is required for the CVaR benchmark tests.

Made with Cursor

v-atharva and others added 3 commits March 27, 2026 09:09
… benchmark, pyfolio

- Add CompositeSRLoss: Sharpe + price-action S/R + psychological levels +
  macro regime + optional SEC fundamental alignment
- Extend Trainer to pass input features and fundamentals to the loss;
  include composite loss parameters in optimizer when applicable
- SEC pipeline (edgartools): fetch 10-K/10-Q/8-K, XBRL-derived features,
  composite scores; run_sec_collection CLI and Parquet cache
- CVaR benchmark (CVXPY): rolling Mean-CVaR weights vs LSTM allocations
- pyfolio-reloaded: weights/returns to tearsheets and strategy comparison
- Config: CompositeSRLoss and CVaRBenchmark hparams; sec_filings_dir paths
- Dependencies: cvxpy, edgartools, pyfolio-reloaded, empyrical-reloaded
- Unit tests for composite loss, CVaR, SEC helpers, pyfolio conversion

Made-with: Cursor
…ate, data-driven robustness

- Add TimeframeImportanceFn MLP: learnable lookback→importance weights
  (longer-period S/R levels carry more weight by default)
- Add _detect_pivots(): rolling-window pivot scores across [5,10,21,42,63,105d]
- Add MacroOverrideGate: adaptive omega in (0,1) that re-scales penalty weights
  based on macro rate-of-change (extreme macro → macro penalty dominates)
- Sector-aware S/R scaling via sector_assignment_50.csv
- Per-ticker macro sensitivity weighting via ticker_macro_rankings.csv
- Cross-ticker correlation guard (pre-computed from ret_train)
- Extract shared _compute_delta_macro() helper
- All features off by default (backward-compatible)
- 28 tests added covering multi-TF, gate, sector, sensitivity, correlation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant