All problems
CVaR Linearization
Problem
Evaluate the Rockafellar-Uryasev CVaR linearization at a given threshold.
Return v + sum(max(0, loss - v)) / (alpha * n), where v is the VaR candidate, alpha the tail level, and n the number of scenarios. Minimizing this over v yields the CVaR.
Hint
Only losses above the threshold contribute to the tail average.
Test cases
case 1
in: [[1,2,3,4],2,0.5]
expected: 3.5
case 2
in: [[0.5,1,1.5],1,0.25]
expected: 1.6666666666666665
case 3
in: [[2,2],2,0.5]
expected: 2
Starter codePython
def cvar_linearized(losses, v, alpha):
# Your code here
pass3 test cases · run your code against them in the editor