All problems
CVaR Return
Problem
Compute the conditional value at risk of a return distribution at level alpha.
Sort the returns and average the worst ceil(alpha * n) of them, using at least one return. An empty list returns 0.0.
Hint
CVaR averages the tail, not the threshold, so it is a coherent risk measure.
Test cases
case 1
in: [[1,2,3,4],0.5]
expected: 1.5
case 2
in: [[5],0.1]
expected: 5
case 3
in: [[],0.5]
expected: 0
case 4
in: [[-2,1,3,10,7],0.4]
expected: -0.5
Starter codePython
import math
def cvar_return(returns, alpha):
# Your code here
pass4 test cases · run your code against them in the editor