Skip to content
DeepForgeby svx
All problems
EasyTime Seriests-055

Expected Shortfall Normal

Problem

Compute the expected shortfall (average loss beyond VaR) for normal returns: ES = -mu + sigma * phi(z) / (1 - c), where phi is the standard normal density, z is the lower-tail quantile, and c is the confidence level.

Return 0.0 when c >= 1.

Hint

Expected shortfall is always at least as large as VaR for the same confidence.

Test cases

case 1
in: [0,1,-1.6448536269514722,0.95]
expected: 2.0627128075074257
case 2
in: [0.01,0.02,-1.96,0.975]
expected: 0.036752755466761135
case 3
in: [0,0,-1.5,0.9]
expected: 0
case 4
in: [0,1,-2,1]
expected: 0
Starter codePython
import math
def expected_shortfall_normal(mu, sigma, z, c):
    # Your code here
    pass

4 test cases · run your code against them in the editor