Portfolio optimization is one of the oldest problems in quantitative finance, but applying it well to a specific asset class — in this case Treasury instruments — requires careful handling of forecast data, rebalancing logic, and constraints that generic optimizers don't account for. This case study walks through how I built a Treasury portfolio optimizer deployed as an interactive Streamlit application.
At the heart of the tool is classic Markowitz mean-variance optimization: given expected returns and a covariance matrix of Treasury instruments across maturities, the model finds the portfolio weights that minimize risk for a given expected return (or maximize the Sharpe ratio along the efficient frontier).
Expected returns aren't pulled from a static historical average — they're generated from Blue Chip Financial Forecasts survey data stored in a MariaDB database, giving the model a forward-looking view that updates as new consensus forecasts are published.
Beyond a one-time optimal allocation, the tool includes rebalancing logic for existing portfolios and a separate workflow for allocating new capital without fully unwinding current positions — a feature built specifically after client feedback.
Streamlit lets the entire optimization pipeline live behind a clean, interactive interface with no separate frontend build — sliders for risk tolerance, live efficient frontier plots, and downloadable allocation tables, all from pure Python.