A Python-based multi-asset market risk engine for VaR, Expected Shortfall, volatility forecasting, stress testing, risk attribution, and regime-aware portfolio analysis.
Quant Risk Lab analyzes the risk and performance of four multi-asset portfolios across different market conditions.
The project combines portfolio construction, downside risk measurement, volatility modeling, VaR backtesting, stress testing, risk attribution, and market regime analysis.
The main research question is:
How reliable are standard market risk models when applied to multi-asset portfolios across different market regimes?
The project uses daily market data from Yahoo Finance across multiple asset classes:
- Equities:
SPY,QQQ - Bonds:
TLT,IEF - Credit:
HYG,LQD - Gold:
GLD - Crypto:
BTC-USD,ETH-USD
Four portfolios are compared:
- 60/40 Portfolio: traditional equity and bond allocation
- Risky Portfolio: higher exposure to equities, growth stocks, high-yield credit, and Bitcoin
- Defensive Portfolio: diversified allocation with bonds and gold
- Crypto-Enhanced Portfolio: balanced allocation with a small crypto sleeve
The analysis includes:
- Portfolio returns and drawdowns
- Annualized return, volatility, and Sharpe ratio
- Historical, Gaussian, and Student-t VaR
- Historical Expected Shortfall
- Rolling, EWMA, and GARCH volatility forecasting
- Historical VaR backtesting
- Kupiec test for VaR model calibration
- Scenario-based stress testing
- Risk contribution and volatility attribution
- Market regime classification using rolling volatility and drawdown
The main findings are:
| Question | Result |
|---|---|
| Best full-sample Sharpe ratio | Crypto-Enhanced Portfolio |
| Highest annualized return | Risky Portfolio |
| Lowest annualized volatility | Defensive Portfolio |
| Highest Historical ES 95% | Risky Portfolio |
| Worst stress-test loss | Risky Portfolio |
| Highest latest GARCH volatility | Risky Portfolio |
The Crypto-Enhanced Portfolio achieved the strongest full-sample risk-adjusted performance, while the Risky Portfolio delivered the highest annualized return but also carried the highest tail risk, stress-test vulnerability, and latest GARCH volatility estimate.
The Defensive Portfolio had the lowest volatility and the most stable risk profile, but also produced the lowest annualized return.
The project shows that portfolio risk is multi-dimensional.
A portfolio can look attractive based on average return and Sharpe ratio, while still being exposed to significant tail losses, stress-test losses, or regime-specific weakness.
The regime analysis also shows that high volatility is not always negative. In this framework, crisis periods are separated using a drawdown rule, so the High Volatility regime also captures rebound and recovery periods after market stress.
Overall, the analysis confirms that professional portfolio risk management requires more than one metric. VaR, Expected Shortfall, volatility models, backtesting, stress testing, attribution, and regime analysis each reveal a different part of the risk profile.
quant-risk-lab/
├── notebooks/
│ ├── 01_data_download.ipynb
│ ├── 02_portfolio_construction.ipynb
│ ├── 03_var_expected_shortfall.ipynb
│ ├── 04_volatility_forecasting.ipynb
│ ├── 05_var_backtesting.ipynb
│ ├── 06_stress_testing.ipynb
│ ├── 07_risk_attribution.ipynb
│ ├── 08_regime_analysis.ipynb
│ └── 09_executive_summary.ipynb
├── data/
│ ├── raw/
│ └── processed/
├── reports/
├── figures/
├── src/
├── requirements.txt
├── environment.yml
├── .gitignore
└── README.md
The notebooks are designed to be read and run in order:
-
Data Download
Downloads and cleans market data. -
Portfolio Construction
Builds portfolio returns and performance metrics. -
VaR & Expected Shortfall
Estimates downside risk using multiple VaR methods and Expected Shortfall. -
Volatility Forecasting
Compares rolling volatility, EWMA volatility, and GARCH volatility. -
VaR Backtesting
Tests Historical VaR reliability using violation rates and the Kupiec test. -
Stress Testing
Measures portfolio losses under hypothetical market stress scenarios. -
Risk Attribution
Decomposes portfolio volatility into asset-level risk contributions. -
Regime Analysis
Studies portfolio behavior across normal, low-volatility, high-volatility, and crisis regimes. -
Executive Summary
Summarizes the main findings of the full project.
Clone the repository:
git clone https://github.com/giannandreadestefano/quant-risk-lab.git
cd quant-risk-labInstall dependencies with pip:
pip install -r requirements.txtOr create a Conda environment:
conda env create -f environment.yml
conda activate quant-risk-labThen open Jupyter:
jupyter notebookRun the notebooks in order from 01 to 09.
- Python
- pandas
- NumPy
- SciPy
- matplotlib
- yfinance
- statsmodels
- arch
- Jupyter Notebook
- Git / GitHub
The project generates:
- Cleaned price and return datasets in
data/ - Risk and performance tables in
reports/ - Portfolio charts and risk visualizations in
figures/ - A final executive summary in
reports/executive_summary.csv
Built a Python-based multi-asset risk analytics engine covering portfolio construction, VaR, Expected Shortfall, volatility forecasting, VaR backtesting, stress testing, risk attribution, and regime-aware portfolio analysis.



