3.2 KiB
3.2 KiB
Portfolio AutoResearch
Adapted from Karpathy's autoresearch for macro-based portfolio optimization.
Setup
To set up a new experiment, work with the user to:
- Agree on a run tag: propose a tag based on today's date (e.g.
mar28). - Read the in-scope files: The repo is small:
README.md— contextprepare.py— fixed data prep, feature engineering, evaluation, benchmarks. Do not modify.train.py— the file you modify. Model, features, optimization parameters.
- Verify data exists: Check that
../thesis_portfolio_opt/data/raw/prices.csvandmacro.csvexist. If not, runuv run python prepare.py. - Initialize results.tsv: Create
results.tsvwith the header row if it doesn't exist. - Confirm and go: Confirm setup looks good.
Experimentation
Each experiment trains ML models and runs a strict out-of-sample backtest (train ≤2021, test 2022-2024). Total runtime should be under 2 minutes.
What you CAN do:
- Modify
train.py— the EXPERIMENT CONFIGURATION section. Everything is fair game: model type, hyperparameters, feature selection, optimization parameters, shrinkage, rebalancing frequency.
What you CANNOT do:
- Modify
prepare.py. It contains fixed evaluation, data loading, and backtesting. - Install new packages.
- Access test data during training.
The goal: get the highest OOS Sharpe ratio.
Benchmarks (these are your targets):
- Equal Weight: Sharpe ≈ 0.20
- 60/40: Sharpe ≈ 0.56
- SPY: Sharpe ≈ 0.67
Simplicity criterion: All else equal, simpler is better. A small Sharpe improvement that adds ugly complexity is not worth it.
Output format
The script prints:
RESULT: sharpe=X.XXXX ic=X.XXXX dir_acc=X.XXXX ann_return=X.XXXX max_dd=X.XXXX description="..."
Extract with: grep "^RESULT:" run.log
Logging results
Log to results.tsv (tab-separated):
experiment sharpe ic dir_acc status description
Status: keep, discard, or crash.
The experiment loop
LOOP FOREVER:
- Look at current
train.pyandresults.tsv - Propose a hypothesis
- Edit the EXPERIMENT section of
train.py - Run:
uv run python train.py > run.log 2>&1 - Read:
grep "^RESULT:" run.log - Log to
results.tsv - If Sharpe improved over best-so-far → keep
- If not → revert
train.py - Repeat
NEVER STOP. The user may be sleeping. Run until manually interrupted.
Ideas to try
- Different models: Lasso, Ridge, ElasticNet, XGBoost, LightGBM, RF, SVR
- Macro-only vs momentum-only vs all features
- Feature selection: top-K by mutual information
- PCA dimensionality reduction (164 → 20 components)
- Different prediction horizons: 5d, 21d, 63d
- Risk aversion sweep: λ = 1, 2, 5, 10, 20
- Shrinkage toward historical mean: α = 0.1, 0.3, 0.5, 0.7
- Ensemble: average predictions from 3+ models
- Regime-conditional: separate models for high/low VIX
- Walk-forward retraining: retrain every quarter using rolling window
- Non-linear features: VIX × momentum, log(VIX), momentum²
- Transaction cost sensitivity: 5, 10, 20, 50 bps
- Rebalancing frequency: weekly vs monthly vs quarterly
- Max weight constraint: 0.2, 0.3, 0.4, 0.5
- Target rank prediction instead of raw returns