A Python research toolkit for portfolio construction, risk analysis, stochastic simulation and portfolio insurance.
Portfolio Optimization Lab is a reproducible, notebook-driven exploration of quantitative portfolio theory. It combines a shared Python toolkit with eight focused research notebooks and a curated gallery of executed results.
The project uses monthly value-weighted returns for the 30 industry portfolios from the Kenneth R. French Data Library. The included dataset spans July 1926 to December 2018.
| Area | What is explored |
|---|---|
| Portfolio construction | Two-asset opportunity sets, efficient frontiers, global minimum variance and tangency portfolios |
| Estimation risk | Sensitivity of optimal allocations to expected-return assumptions |
| Stochastic modelling | Geometric Brownian motion and Monte Carlo price paths |
| Portfolio insurance | CPPI, static floors, drawdown constraints and floor-breach analysis |
| Liability valuation | Discount factors, present value and funding ratios |
| Diversification | Rolling industry correlations and market-cap-weighted extensions |
Source: Notebook 01 — Efficient frontier.
Source: Notebook 05 — CPPI and drawdown constraints.
Source: Notebook 05 — CPPI and drawdown constraints.
Source: Notebook 05 — CPPI and drawdown constraints.
Source: Notebook 06 — Monte Carlo CPPI.
Source: Notebook 08 — Limits of diversification.
Browse all figures: outputs/README.md.
Run the notebooks in numerical order. Each notebook uses the shared implementation via import risk_kit as rk.
| # | Notebook | Focus |
|---|---|---|
| 01 | Efficient frontier | Two-asset and N-asset frontiers, GMV and reference portfolios |
| 02 | Global minimum variance | Estimation risk and covariance-driven allocation |
| 03 | Maximum Sharpe ratio | Tangency portfolio, CML and return sensitivity |
| 04 | Random walks and GBM | Stochastic price paths and simulation assumptions |
| 05 | CPPI and drawdown constraints | Historical CPPI, risky allocation and drawdown floors |
| 06 | Monte Carlo CPPI | Scenario paths, terminal wealth and floor breaches |
| 07 | Liabilities and funding ratio | Discounting, present value and funding sensitivity |
| 08 | Limits of diversification | Rolling correlations and diversification behaviour |
See notebooks/README.md for the complete notebook guide, conventions and execution notes.
git clone https://github.com/skate-m/portfolio-optimization-lab.git
cd portfolio-optimization-labpython -m venv .venv
# Linux / macOS
source .venv/bin/activate
# Windows PowerShell
# .venv\\Scripts\\Activate.ps1
python -m pip install --upgrade pip
pip install -r requirements.txtjupyter labRun JupyterLab from the repository root so notebooks can import risk_kit.py and resolve the bundled data paths. For reproducible results, use Kernel → Restart Kernel and Run All Cells.
pytest -qGitHub Actions runs the test suite on pushes and pull requests to main.
portfolio-optimization-lab/
├── data/
│ ├── ind30_m_vw_rets.csv
│ └── README.md
├── notebooks/
│ ├── README.md
│ ├── 01_efficient_frontier.ipynb
│ ├── 02_global_minimum_variance.ipynb
│ ├── 03_maximum_sharpe_ratio.ipynb
│ ├── 04_random_walk_gbm.ipynb
│ ├── 05_cppi_drawdown_constraints.ipynb
│ ├── 06_cppi_monte_carlo.ipynb
│ ├── 07_liabilities_funding_ratio.ipynb
│ └── 08_limits_of_diversification.ipynb
├── outputs/
│ ├── *.png
│ ├── *.svg
│ └── README.md
├── tests/
│ └── test_risk_kit.py
├── .github/workflows/tests.yml
├── risk_kit.py
└── requirements.txt
risk_kit.py contains reusable implementations for:
- Industry data loading and optional market-cap index construction.
- Drawdown, skewness, kurtosis, historical VaR and Gaussian VaR.
- Annualised return, volatility, Sharpe ratio and summary statistics.
- Portfolio return and volatility calculations.
- Long-only GMV, maximum-Sharpe and efficient-frontier optimisation.
- Geometric Brownian motion simulation.
- CPPI backtesting with static and ratcheting drawdown floors.
- Liability discounting, present value and funding ratios.
Conventions: returns are decimal simple returns (0.01 = 1%). Annual rates and expected returns are decimals. The source CSV stores returns in percentage points; get_ind_returns() converts them to decimals.
The bundled data/ind30_m_vw_rets.csv file contains 1,110 monthly observations across 30 industries, from July 1926 through December 2018. Source: Kenneth R. French Data Library.
Optional market-cap-weighted extensions require two additional source files that are not bundled:
ind30_m_nfirms.csv— number of firms by industry.ind30_m_size.csv— average firm size by industry.
The optional sections explain how to provide these files. Missing values are not fabricated. See data/README.md.
- Efficient-frontier examples estimate expected returns and covariance from January 1996–December 2000.
- Monthly returns are geometrically annualised; monthly covariance is multiplied by 12.
- Optimisation examples use fully invested, long-only weights bounded between zero and one.
- The 3% annual risk-free rate is an illustrative assumption, not a live market quote.
- GBM assumes constant drift and volatility with lognormal returns; it omits jumps, volatility clustering and regime changes.
- CPPI is exposed to gap and discrete-rebalancing risk; a floor is not guaranteed in real markets.
- Liability valuation uses a flat discount curve and simplified annual compounding.
- Backtests omit transaction costs, taxes, market impact, liquidity constraints and out-of-sample execution.
This repository is an educational quantitative-finance research project, not investment advice. Historical results and simulated scenarios do not predict future performance.
Built for learning, experimentation and reproducible quantitative research.




