I wrote a simple function in Python to calculate the exponentially weighted mean:
def test(): x = [1,2,3,4,5] alpha = 0.98 s_old = x for i in range(1, len(x)): s = alpha * x[i] + (1- alpha) * s_old s_old = s return s
However, how can I calculate the corresponding SD?
You can use the following recurrent formula:
Here xi is your observation in the i-th step, μi−1 is the estimated EWM, and Si−1 is the previous estimate of the variance. See Section 9 here for the proof and pseudo-code.