A modular Python framework for comparing covariance matrix estimators and portfolio allocation algorithms using rolling out-of-sample backtesting.
The project is designed to evaluate the impact of covariance estimation on portfolio construction in a high-dimensional setting, with a focus on Global Minimum Variance (GMV) and Hierarchical Risk Parity (HRP) portfolios.
- Sample Covariance
- Ledoit–Wolf Linear Shrinkage
- Quadratic-Inverse Shrinkage (QIS)
- Equal Weight
- Global Minimum Variance (GMV)
- Hierarchical Risk Parity (HRP)
- Rolling walk-forward backtesting
- Annualized return
- Annualized volatility
- Sharpe ratio
- Maximum drawdown
- Python
- NumPy
- Pandas
- SciPy
- scikit-learn
- CVXPY
- yfinance
flowchart TD
A([Returns])
A --> B["Covariance Estimator:
• Sample
• Linear Shrinkage
• Nonlinear Shrinkage"]
B --> C([Covariance Matrix])
C --> D["Portfolio Allocator:
• Equal Weight
• Global Minimum Variance
• Hierarchical Risk Parity"]
D --> E([Rolling Backtest])
E --> F([Performance Metrics])
Clone the repository:
git clone https://github.com/<your-username>/portfolio-optimization.git
cd portfolio-optimizationInstall the required packages:
pip install -r requirements.txtRun the demonstration notebook:
jupyter notebook notebooks/demo.ipynbAlternatively, open the repository in VS Code and run
notebooks/demo.ipynb
The notebook is self-contained and can be run from top to bottom.
src/
├── allocators/
├── backtesting/
├── covariance/
├── metrics/
└── utils/
notebooks/
tests/
data/
The framework supports systematic benchmarking of different combinations of
- covariance estimators,
- portfolio allocation methods,
- hierarchical clustering linkage methods,
using rolling out-of-sample evaluation.
The benchmark produces a comparison table containing
| Portfolio | Annualized Return | Annualized Volatility | Sharpe Ratio | Maximum Drawdown |
|---|---|---|---|---|
| Sample | GMV | ... | ... | ... | ... |
| Linear Shrinkage | HRP (average) | ... | ... | ... | ... |
as well as cumulative wealth plots for each portfolio strategy.