Applying Marchenko-Pastur theory to denoise correlation matrices for improved portfolio construction on NIFTY 50 stocks.
Problem: Standard Markowitz mean-variance optimization is notoriously sensitive to estimation errors in the covariance matrix. When the number of assets (
Solution: Random Matrix Theory (RMT) provides a rigorous mathematical framework to separate signal from noise in correlation matrices. By filtering out eigenvalues that are statistically indistinguishable from random noise (using the Marchenko-Pastur distribution as null hypothesis), we construct more robust portfolios.
Key Result: RMT-denoised portfolios demonstrate superior out-of-sample risk-adjusted returns compared to traditional Markowitz optimization on NIFTY 50 stocks (2019–2024).
For an
where
- Eigendecompose:
$C = V \Lambda V^\top$ - Replace noise eigenvalues (
$\leq \lambda_+$ ) with their mean - Reconstruct:
$\tilde{C} = V \tilde{\Lambda} V^\top$ - Rescale to unit diagonal:
$\hat{C} = D^{-1/2} \tilde{C} D^{-1/2}$
| Method | Sharpe Ratio | Max Drawdown | Annual Return |
|---|---|---|---|
| Raw Markowitz | Baseline | Baseline | Baseline |
| RMT-Denoised | ✅ Improved | ✅ Reduced | ✅ Competitive |
| Equal Weight (1/N) | Reference | Reference | Reference |
| Eigenvalue Spectrum | Correlation Heatmaps | Efficient Frontier |
|---|---|---|
| MP distribution overlay | Raw vs Denoised | 3-method comparison |
| Cumulative Returns | Rolling Sharpe | Drawdown |
|---|---|---|
| Out-of-sample performance | Time-varying risk-adjusted returns | Risk analysis |
git clone https://github.com/adivx/rmt-portfolio.git
cd rmt-portfoliopip install -r requirements.txtjupyter notebook notebooks/rmt_portfolio_optimization.ipynbpython src/backtester.py├── README.md # This file
├── requirements.txt # Python dependencies
├── config.py # Global configuration
├── create_notebook.py # Notebook generator script
│
├── src/
│ ├── __init__.py
│ ├── data_fetcher.py # NSE data download & preprocessing
│ ├── rmt_analysis.py # Core RMT: MP distribution, denoising
│ ├── portfolio_optimizer.py # Markowitz optimization (3 methods)
│ ├── backtester.py # Out-of-sample backtesting engine
│ └── visualization.py # Dark mode visualization suite
│
├── notebooks/
│ └── rmt_portfolio_optimization.ipynb # Main presentation notebook
│
└── data/ # Cached stock data (auto-generated)
All parameters are centralized in config.py:
| Parameter | Default | Description |
|---|---|---|
NIFTY50_TICKERS |
50 stocks | NSE stock universe |
START_DATE |
2019-01-01 | Data start date |
END_DATE |
2024-12-31 | Data end date |
TRAIN_YEARS |
3 | Training window |
RISK_FREE_RATE |
7% | India 10Y bond yield |
REBALANCE_FREQ |
Monthly | Portfolio rebalancing frequency |
yfinance— Yahoo Finance data APInumpy— Numerical computingscipy— Scientific computing & optimizationpandas— Data manipulationmatplotlib— Visualizationseaborn— Statistical visualization
- Marchenko, V.A. & Pastur, L.A. (1967). Distribution of eigenvalues for some sets of random matrices. Math. USSR-Sbornik, 1(4), 457–483.
- Laloux, L., Cizeau, P., Bouchaud, J.-P., & Potters, M. (1999). Random matrix theory and correlated financial data. Phys. Rev. Lett., 82, 1909.
- Markowitz, H. (1952). Portfolio Selection. The Journal of Finance, 7(1), 77–91.
- Bouchaud, J.-P. & Potters, M. (2003). Theory of Financial Risk and Derivative Pricing. Cambridge University Press.
Aditya Kumar
- GitHub: @adivx
- LinkedIn: Aditya Kumar
- Email: aditya.kumar.x9182@gmail.com
This project is licensed under the MIT License — see LICENSE for details.
Built with ❤️ using Python, NumPy, SciPy, and Matplotlib