All problems
Volatility Scaling
Problem
Scale a return series to a target volatility using the realized volatility sqrt(sum(r^2)): each return becomes r * target_vol / realized_vol.
Return an empty list for empty returns; if realized volatility is zero, return a list of zeros of the same length.
Hint
Scaling preserves the signs and the shape of the return path.
Test cases
case 1
in: [[0.01,-0.02,0.03],0.05]
expected: [0.013363062095621218,-0.026726124191242435,0.04008918628686366]
case 2
in: [[0,0],0.1]
expected: [0,0]
case 3
in: [[0.1],0.2]
expected: [0.20000000000000004]
case 4
in: [[],0.1]
expected: []
Starter codePython
def volatility_scaling(returns, target_vol):
# Your code here
pass4 test cases · run your code against them in the editor