To truly understand quantitative finance, one must build its foundational models from scratch. Following our theoretical breakdown of Value at Risk (VaR) and Conditional Value at Risk (CVaR), we are now bridging the gap between mathematical theory and practical implementation.
We have open-sourced a complete Python environment to empirically verify the core claims of our previous research: the instability of VaR, its dangerous violation of subadditivity, and the exact mechanics behind the Basel Committee's FRTB regulatory shift.
Step 1: Monte Carlo Simulation and Estimator Stability
In complex portfolios containing options and non-linear payoffs, risk cannot be computed with simple closed-form equations. We simulate 10,000 daily P&L paths for a portfolio that is long delta and short gamma (exhibiting negative convexity and tail risk).
The script strictly computes the 99% VaR and the 99% CVaR using direct sorting algorithms.
- Calculation Match: For 10,000 scenarios at a 99% confidence level, the 99% VaR (the 100th worst loss) evaluates to 2,602.11. The 99% CVaR (the average of the worst 100 losses) evaluates to 3,189.63. Comparing the direct sorting method to statistical quantile functions, the two methods match exactly.
- Statistical Stability: Running this simulation across 20 independent random seeds reveals that CVaR is actually a more stable estimator than VaR. Because CVaR aggregates 100 observations instead of relying on a single quantile threshold, its relative statistical noise is only 1.9%, compared to 2.3% for VaR.
Step 2: The Subadditivity Violation (Mathematical Coherence)
The fundamental flaw of VaR is that it penalizes diversification. We recreate the classic analytical counter-example: two independent corporate bonds, each with a 0.8% default probability and a 100.00 loss magnitude.
- Analytical Failure: Because the default probability (0.8%) is lower than the 1% tail threshold, the 99% VaR for Bond A is 0.00, and for Bond B is 0.00. However, the probability of at least one bond defaulting pushes the 99% VaR of the combined portfolio to 100.00. VaR mathematically penalizes holding a diversified portfolio.
- CVaR Coherence: On the exact same portfolio, the 99% CVaR for each individual bond is 80.00 (a sum of 160.00). The 99% CVaR of the combined portfolio evaluates to 100.64. Thus, CVaR inherently preserves subadditivity and accurately reflects the benefits of diversification.
- Monte Carlo Frequency: When generating 2,000 random portfolio pairings, VaR violated subadditivity in 3.9% of the cases. As mathematically proven, CVaR violated subadditivity in 0.0% of the tested scenarios.
Step 3: The FRTB Regulatory Shift
The Basel Committee's Fundamental Review of the Trading Book (FRTB) mandates a shift from 99% VaR to a 97.5% Expected Shortfall (CVaR). We simulate different market environments to test the capital gap this creates.
- Under Normal Markets: If markets are perfectly Gaussian (normal distribution), the ratio between the 97.5% ES and the 99% VaR is 1.005. The regulatory shift barely changes the required capital.
- Under Fat Tails: As the tail becomes thicker (simulating realistic financial markets), the capital gap diverges. For a Student-t distribution with ν=3, the 97.5% ES to 99% VaR ratio increases to 1.111. The ratio consistently decreases back toward 1.00 as the distribution approaches normality.
- The 2008 Stress Scenario: We simulated a mixture model where 99% of returns are normal, but 1% represent a severe market crash. Here, the 99% VaR registered at 2,939,359. However, the 97.5% ES aggressively aggregated the severity of the crisis, landing at 4,806,174. This yields a ratio of 1.64, perfectly illustrating why regulators consider VaR "blind" to the true magnitude of extreme market shocks.