Skip to content

Latest commit

 

History

17 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quant Risk Lab

A Python-based multi-asset market risk engine for VaR, Expected Shortfall, volatility forecasting, stress testing, risk attribution, and regime-aware portfolio analysis.

Project Overview

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?

Asset Universe

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

Portfolios Analyzed

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

Methodology

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

Main Results

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.

Key Insights

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.

Key Figures

Cumulative Portfolio Returns

Cumulative Portfolio Returns

Portfolio Drawdowns

Portfolio Drawdowns

VaR Backtesting Violations

VaR Backtesting Violations

Market Regime Timeline

Market Regime Timeline

Repository Structure

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

Notebook Workflow

The notebooks are designed to be read and run in order:

  1. Data Download
    Downloads and cleans market data.

  2. Portfolio Construction
    Builds portfolio returns and performance metrics.

  3. VaR & Expected Shortfall
    Estimates downside risk using multiple VaR methods and Expected Shortfall.

  4. Volatility Forecasting
    Compares rolling volatility, EWMA volatility, and GARCH volatility.

  5. VaR Backtesting
    Tests Historical VaR reliability using violation rates and the Kupiec test.

  6. Stress Testing
    Measures portfolio losses under hypothetical market stress scenarios.

  7. Risk Attribution
    Decomposes portfolio volatility into asset-level risk contributions.

  8. Regime Analysis
    Studies portfolio behavior across normal, low-volatility, high-volatility, and crisis regimes.

  9. Executive Summary
    Summarizes the main findings of the full project.

How to Run

Clone the repository:

git clone https://github.com/giannandreadestefano/quant-risk-lab.git
cd quant-risk-lab

Install dependencies with pip:

pip install -r requirements.txt

Or create a Conda environment:

conda env create -f environment.yml
conda activate quant-risk-lab

Then open Jupyter:

jupyter notebook

Run the notebooks in order from 01 to 09.

Technologies Used

  • Python
  • pandas
  • NumPy
  • SciPy
  • matplotlib
  • yfinance
  • statsmodels
  • arch
  • Jupyter Notebook
  • Git / GitHub

Project Outputs

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

CV Summary

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.

About

A Python-based multi-asset market risk engine for VaR, Expected Shortfall, volatility forecasting, stress testing, and regime-aware risk analysis.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages