Quantitative Finance
Quant Finance · Python · Streamlit

Building a Treasury Portfolio Optimizer with Markowitz Theory and Streamlit

By Samuel Alarcón · Econometrician & Data Scientist

Applying portfolio optimization well to a specific asset class 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 app.

The optimization core

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.

Where the forecasts come from

Expected returns are 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.

Rebalancing and new capital allocation

The tool includes rebalancing logic for existing portfolios and a separate workflow for allocating new capital without fully unwinding current positions.

View on GitHubDiscuss a similar project