Try it: https://huggingface.co/spaces/drimranbhatti/portfolio-optimizer
Inspiration
Most portfolio optimizers show the in-sample efficient frontier and stop there, which flatters the fanciest method. Investment committees and CFOs managing surplus cash need to see what happens after the fit.
What it does
You pick stocks from 13 large US names plus SPY, choose a fitting period and a weight cap, and the app builds minimum-variance, maximum-Sharpe, risk-parity and equal-weight portfolios (long-only). It then tests all four on the following period and reports return, volatility, Sharpe ratio and maximum drawdown, with the efficient frontier and a growth-of-$1 chart.
How I built it
- Methods come from my portfolio-optimization-lab (Markowitz, Black-Litterman, Kelly, risk parity, HRP, random-matrix covariance denoising, walk-forward backtests net of costs), built during my WorldQuant University MScFE.
- SciPy SLSQP for the constrained optimisations; daily prices 2012-2026 bundled with the app.
- Gradio-Lite runs the Python in the visitor's browser, so hosting is free and nothing entered leaves the device.
Challenges I ran into
Maximum-Sharpe weights pile into recent winners; the weight cap and the out-of-sample split make that risk visible instead of hiding it.
Accomplishments that I'm proud of
On the default 2015-2021 fit and 2022-2026 test, risk parity and equal weight beat maximum Sharpe out of sample on Sharpe ratio and drawdown: the classic estimation-error lesson, shown live.
What I learned
Simple, robust allocations often survive contact with new data better than optimised ones.
What's next
Add HRP, Black-Litterman views and transaction costs from the full lab.
Built by Dr. Muhammad Imran Bhatti, PhD (FCMA, FCPA), fractional CFO and quant. Code: https://github.com/drimranbhatti/portfolio-optimization-lab Educational tool, not investment advice.