Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PortfolioPilot — ML Portfolio Optimization

Regime-Aware Mean-Variance Optimization using Hidden Markov Models + LightGBM + Markowitz MVO

Python LightGBM Streamlit License: MIT Demo


🧠 What This Does

Financial markets alternate between latent regimes — bull, bear, sideways — that alter return distributions and asset correlations. Classical Markowitz ignores this, leading to poor out-of-sample performance.

This project chains three ML components:

SPY Returns ──► [GaussianHMM] ──► Market Regime (Bull / Bear / Sideways)
                                             │
Stock Features ──► [LightGBM] ──► Expected Returns μ
                                             │
              [Regime-Conditioned Σ + μ] ──► [Markowitz MVO] ──► Weights

📊 Results (2019–2024 Backtest)

Strategy Ann. Return Sharpe Sortino Max DD
ML + Regime MVO 18.4% 1.61 2.34 −13.2%
Classical MVO 15.1% 1.17 1.71 −17.4%
Equal Weight 13.9% 0.99 1.40 −22.1%
SPY Benchmark 14.2% 0.97 1.39 −33.9%

30-stock S&P 500 universe, monthly rebalancing, strict walk-forward validation.


🚀 Quick Start

git clone https://github.com/aashshahh/portfolio-optimization-ml
cd portfolio-optimization-ml
pip install -r requirements.txt

# Run full pipeline
jupyter notebook notebooks/portfolio_optimization_pipeline.ipynb

# Launch interactive demo
streamlit run app.py

🗂️ Structure

portfolio-optimization-ml/
├── notebooks/
│   └── portfolio_optimization_pipeline.ipynb   ← Full end-to-end pipeline
├── data/                                        ← Generated by notebook
├── results/                                     ← Saved plots
├── docs/index.html                              ← GitHub Pages demo site
├── app.py                                       ← Streamlit interactive app
└── requirements.txt

🔬 Method

1. HMM Regime Detection — GaussianHMM (3 states) on SPY return/vol/momentum features. No labels required. Learns bull/bear/sideways from data.

2. LightGBM Walk-Forward — 14 features per stock (momentum, RSI, vol, beta, regime dummies). Strict walk-forward: 3Y train → 1Y test, 5 folds. Metric: Information Coefficient (Spearman rank correlation).

3. Regime-Conditioned MVOmax w'μ - λ/2 · w'Σw where μ = ML predictions, Σ = covariance estimated from same-regime historical returns + Ledoit-Wolf shrinkage. Solved via scipy SLSQP.


⚠️ Limitations

  • No transaction costs modeled
  • Survivorship bias in universe selection
  • Regime detection is backward-looking
  • Not validated for live trading

📚 References

  • Hamilton (1989) — HMM for regime switching
  • Ang & Timmermann (2012) — Regime changes in financial markets
  • Ledoit & Wolf (2004) — Covariance shrinkage
  • Markowitz (1952) — Portfolio selection

Built for educational purposes. Not financial advice.

About

ML powered portfolio optimization app with regime detection, return prediction, and risk aware allocation using Markowitz + shrinkage.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages