All problems
EWMA Volatility Update
Problem
Update an exponentially weighted moving average volatility estimate: sigma = sqrt(lam * prev_variance + (1 - lam) * ret^2).
Return 0.0 when the weighted variance is negative.
Hint
The decay lam weights yesterday's variance, so lam near 1 produces a smooth series.
Test cases
case 1
in: [0.04,0.03,0.94]
expected: 0.19404638620700979
case 2
in: [0.01,0.1,0.5]
expected: 0.1
case 3
in: [0,0,0.9]
expected: 0
case 4
in: [0.09,0.05,0]
expected: 0.05
Starter codePython
def ewma_volatility_update(prev_variance, ret, lam):
# Your code here
pass4 test cases · run your code against them in the editor