Blog / risk

VaR, SVaR and CVaR: A Practical Python Implementation

March 29, 2026riskpythonquant// 6 min read

Value at Risk (VaR) quantifies the maximum expected loss at a given confidence level over a fixed horizon. Conditional VaR (CVaR), also known as Expected Shortfall, measures the average loss in the tail beyond the VaR threshold — a far more informative measure for fat-tailed return distributions.

Equation

CVaRα=E[RRVaRα]\text{CVaR}_\alpha = -\mathbb{E}[R \mid R \leq \text{VaR}_\alpha]

where α ∈ (0,1) is the confidence level and R is the portfolio return random variable

What is Value at Risk?

VaR at confidence level α answers: "What is the worst loss I should expect on 95% of days?" Historically this is computed by sorting returns and reading the (1-α) percentile.

In []python
Out []:{'var': -0.0231, 'svar': -0.0318, 'cvar': -0.0287}

Stressed VaR (SVaR)

SVaR is a Basel III requirement. It applies the VaR model to a 12-month window of stressed market conditions (typically the 2008–2009 crisis period). We approximate this by using the worst tercile of historical observations.

CVaR (Expected Shortfall)

CVaR does not ask "what is the boundary of the bad days?" — it asks "on the bad days, how bad is it?" This makes it a coherent risk measure (it satisfies sub-additivity, unlike plain VaR) and is preferred by academics and increasingly by regulators under FRTB.

In []python
Out []:{'var_parametric': -0.0219, 'cvar_parametric': -0.0274}

Conclusion

  • Use historical simulation for heavy-tailed assets (crypto, small caps)
  • Use parametric VaR only when returns are demonstrably normal
  • Always report CVaR alongside VaR — it captures tail risk VaR ignores
  • SVaR is a regulatory requirement under Basel III/IV — budget for it
SPY 512.34 +0.82%BTC 68,241 -1.14%VIX 18.42 +3.20%QQQ 438.12 +1.05%GLD 221.07 -0.33%MODEL·PNL +2.41% MTDSPY 512.34 +0.82%BTC 68,241 -1.14%VIX 18.42 +3.20%QQQ 438.12 +1.05%GLD 221.07 -0.33%MODEL·PNL +2.41% MTD