Expected Shortfall vs VaR I have a question about how to compute the Expected Shortfall practically. I know from the theory that the ES is the conditional Expectation of the Loss distribution (conditional on the VaR) and that it is intrinsically greater than the VaR:

ES_α = E[L|L > VaR_α]


Following this formula I have calculated the VaR in R using quantile(loss, probs=0.999) function on my loss distribution. Then I have filtered the loss distribution observations greater than the VaR, filter(loss > VaR), and applied on this filtered loss distribution the expectation formula using sum(x*probability(x)).
However it turns out that the VaR is greater than the ES. How is it possible? Having the Loss distribution how should I calculate VaR and ES? Did I do it wrong?

Simulating from a standard normal distribution as your chart suggests, you should get something like this
set.seed(2022)
loss <- rnorm(10^6)
VaR <- quantile(loss, probs=0.999)
VaR  # about qnorm(0.999) i.e. 3.090232
#    99.9% 
# 3.090315
mean(loss[loss >= VaR]) # about dnorm(qnorm(0.999))/(1-0.999) i.e. 3.36709
# 3.36505

It is not totally clear to me what the probabilities are in sum(x*probability(x)) but assuming the x are losses greater than VaR then what you want is the conditional expectation sum(x*probability(x))/sum(probability(x))
