When the quantile cuts through a group of equal losses
For an integrable loss, the upper-tail Expected Shortfall is
Suppose a portfolio breaks even on 90% of days, loses 10,000 dollars on 7% and loses 50,000 dollars on 3%. At 10,000 dollars, the cumulative probability reaches 97%, so the 95% VaR is 10,000 dollars. The worst 5% includes all 3% of the 50,000 dollars days and two percentage points of the 10,000 dollars days. The 95% ES is therefore
Averaging losses strictly above 10,000 dollars would give 50,000 dollars and describe only the worst 3%. Averaging all losses at or above 10,000 dollars would include 10% of the outcomes. The quantile definition gives the desired 5% tail in both continuous and discrete examples.
Imagine ranking 100 equally weighted days from worst to best. The three days losing 50,000 dollars occupy three slots in the five-day tail. Two more slots are filled by days losing 10,000 dollars, even though seven days share that loss. It does not matter which two days you pick because their losses are identical. That is the discrete reason to count probability mass up to the tail boundary rather than averaging all observations at or above VaR.
A second desk could have the same 95% VaR and a very different expected shortfall. Keep the three worst days at a combined probability of 3%, but let each of them lose 100,000 dollars instead of 50,000. The quantile still lands on 10,000 because the probability below and at that level is unchanged. The worst 5% now averages . That gap is the loss severity information the original 10,000-dollar threshold leaves out.
Verify the discrete calculation
import numpy as np
losses = np.array([0, 10_000, 50_000])
probabilities = np.array([0.90, 0.07, 0.03])
alpha = 0.95
var = losses[np.searchsorted(probabilities.cumsum(), alpha)]
es = var + (probabilities @ np.maximum(losses - var, 0)) / (1 - alpha)
print(var, round(es))