The Claude Quant PlaybookDownload ebookDownload ebook

Expected shortfall (CVaR)

advancedRisk and portfolio5 of 13

Expected shortfall is the average loss in the tail beyond VaR. VaR tells you where the bad days start; expected shortfall tells you how bad they are on average.

Build a trading system with Claude.Download ebook

01The formula

expected shortfall: the average loss on the days that are worse than VaR
value at risk at confidence c
the standard normal density at the quantile z_c
the size of the tail: for example 2.5% of days
the standard deviation of the P&L in money over h days

02See it move

03Where it is used

04Why traders use it

Two portfolios can have the same VaR while one hides a catastrophic tail. Expected shortfall sees the difference, and it is coherent: the risk of a combined book is never more than the sum of its parts.

05Worked example

A $1,000,000 portfolio with daily volatility 1.5% at 97.5% confidence has a VaR of $29,399 and an expected shortfall of $35,067, so the average tail loss is 1.193 times the VaR. For a normal P&L this ES is close to the 99% VaR of $34,895.

06How it is built

  1. Start from the VaR point standard deviations, with .
  2. Average the loss over the tail only: , where .
  3. The integral of from upwards is , so .
  4. Since the tail lies beyond VaR, ES is always at least VaR.

07The common mistake

Estimating it from too little data. At 97.5% only one day in forty is in the tail, so a year of history gives about six tail days to average. Expected shortfall from short samples is very noisy.

08In Python and LaTeX

import numpy as np
from scipy.stats import norm
V, sigma, c, h = 1_000_000, 0.015, 0.975, 1
s = sigma * np.sqrt(h) * V
z = norm.ppf(c)
print(round(s * norm.pdf(z) / (1 - c)), round(z * s))  # ES and VaR
\text{ES}_c = E\big[\,\text{loss} \mid \text{loss} > \text{VaR}_c\big] = \sigma\sqrt{h}\,V\,\frac{n(z_c)}{1 - c}

09Where it fits

Rather not code the maths yourself? Describe your trading idea and let AI build the bot.

Build a bot with AgenKit

The worked example and the model run the same code, so every number matches. Models simplify markets on purpose. This is education, not financial advice.