Expected Shortfall from Return Quantiles and Sign Conventions
Summary
The document explains a sample-based way to estimate Expected Shortfall (ES) from a return distribution: find the lower-tail quantile and average observations below it. It compares this numerical estimate with a normal-distribution formula and identifies the source of the apparent disagreement as a sign convention. For returns, VaR is the left-tail return quantile and ES is the mean return below it; for losses, values are negated, so VaR is taken from the right tail and ES averages losses above that threshold.
The example uses simulated normally distributed returns and shows that the numerical estimate and analytical result have similar magnitudes but opposite signs. The method of averaging tail observations can be applied to an empirical distribution without assuming normality, though it is an estimate based on the available sample and chosen tail probability. The document does not discuss finite-sample uncertainty, alternative ES estimators, or details of conventions for reporting risk as a positive loss.
Key ideas
- Estimate return ES by averaging observations below the selected lower-tail quantile.
- For loss data, negate returns and average observations above the corresponding right-tail VaR threshold.
- Opposite signs between return-based and loss-based ES can reflect conventions rather than a formula error.
- A sample-based estimate can be used when the return distribution has no convenient closed-form solution.
Tags
Full text
# compute Expected Shortfall / Conditional VaR from distribution
# compute Expected Shortfall / Conditional VaR from distribution
I want to compute the Expected Shortfall from a distribution of returns.
I have no closed solution for my distribution of returns, so I wonder if I can simply compute ES by taking the mean of all the values below a certain quantile. From my understanding, this seems to be what the analytical formula also does.
But the problem I have is that the output of the analytical formula for all combinations of mean and standard deviation is always the additive inverse of the numerical approximation. I suspect I somehow used the formula incorrectly. In any case, my main questions are:
- Can I compute the ES the way I do it in the code below? I.e. simply taking the mean of the values below the e.g 95% level? Does this work no matter my return distribution?
- What did i do wrong in the analytical formula?
```
# imports
import numpy as np
import matplotlib.pyplot as plt
import scipy; from scipy import stats
# generating the distribution
mean = 6
std = 1
dist = scipy.stats.norm.rvs(loc=mean, scale=std, size=1_000_000)
# computing VaR and ES: is this correct?
VAR = np.quantile(a=dist, q=0.05)
ES = np.mean(dist[np.where(dist < VAR)])
# plotting and printing
plt.hist(dist, bins=np.linspace(-20,20,100), density=True)
plt.vlines(x=VAR, ymin=0, ymax=.5, label="VAR 95", color="red")
plt.vlines(x=ES, ymin=0, ymax=.5, label="ES 95", color="green")
plt.legend()
plt.show()
print(f"VAR: {VAR}")
print(f"ES: {ES}")
# verifying the ES analytically and printing aswell
def analytical_normal_es(mu, sigma, level):
return -mu + sigma * scipy.stats.norm.pdf(x=scipy.stats.norm.ppf(level)) / level
solES = analytical_normal_es(mean,std,0.05)
print(f"solES: {solES}")
```
outputs
```
VAR: 4.354602809080357
ES: 3.9394240486966927
solES: -3.9372871924925747
```
## Answer by SlavicDoomer (score 2, accepted)
https://quant.stackexchange.com/a/70477
Generally, VaR and ES can been seen from two different points of view:
- $R_t$ are portfolio returns. Then VaR is left quantile (e.g. 0.05) and ES is expected return below this quantile.
- $L_t = -R_t$ are portfolio losses. Then VaR is right quantile (e.g. 0.95) and ES is expected loss above this quantile.
Whenever analytical formulas exist, difference between them should be up to +- sign.Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.