Mean-variance portfolio optimization, from scratch
A research-grade mean-variance toolkit that reproduces the canonical literature. Each routine is checked against an independent reference, to 1e-4 or better.
00Overview
A from-scratch mean-variance optimization library, written to be read as much as run. Every estimator and optimizer is derived in code with a docstring tracing it back to the source paper. It ships as a PyPI package with hosted mkdocs-material documentation and a Streamlit demo.
Validation band
01What it implements
- Closed-form efficient frontier via the Merton A/B/C/D scalars: no solver needed for the unconstrained case.
- Black-Litterman / He-Litterman posterior: combines market-implied equilibrium returns with subjective views.
- Ledoit-Wolf shrinkage of the covariance matrix, at parity with sklearn to 1e-10.
- Walk-forward backtest with turnover tracking and transaction costs: out-of-sample by construction.
02Live chart: efficient frontier
The closed-form frontier (lime), the capital market line from the risk-free rate through the tangency portfolio (amber dashed), and the naive 1/N portfolio sitting inside the frontier.
03Live chart: tangency vs 1/N, out of sample
04Validation story
Every routine is cross-checked against an independent reference, not unit-tested for internal consistency alone. The Black-Litterman posterior reproduces He & Litterman (1999)to 1e-4; the shrinkage estimator matches sklearn's Ledoit-Wolf to 1e-10. Both checks run in CI.
Out of sample, the toolkit reproduces the DeMiguel-Garlappi-Uppal (2009) result: after estimation error, a naive 1/N portfolio is hard to beat. The library surfaces that finding rather than hiding it.