Risk Measurement and Stress Testing
Overview
Systematic risk-measurement methodology covering VaR/CVaR calculation, Monte Carlo simulation, stress-test design, and tail-risk analysis. It provides risk evaluation for backtest results and risk-control constraints for asset allocation.
The measures below are implemented once, with tests, in src/quantlib/risk.py. Call them; do not retype the formulas, because a hand-retyped VaR is where the sign convention silently flips.
from src.quantlib.risk import (
historical_var, parametric_var, historical_cvar,
max_drawdown_analysis, monte_carlo_gbm, analyze_mc_results, fit_gpd_tail,
)
Sign convention
A loss is a positive number, uniformly, across every function in the module:
| Value | Reads as |
|---|---|
historical_var(...) == 0.028 | a 2.8% loss |
historical_cvar(...) == 0.042 | a 4.2% average loss in the tail |
max_drawdown_analysis(...)["max_drawdown"] == 0.325 | a 32.5% peak-to-trough decline |
analyze_mc_results(...)["var"] == 0.224 | a 22.4% loss |
Quantities that are returns rather than losses keep their natural sign and are named *_return (mean_return, `worst_5…