# How to get formulas for EWMA model with M-day records

Given following formula in exponential weighted moving average (EWMA) model i: stock i
t: time t
rit: actual return for stock i at time t

If we only know latest M-day situation, how can we derive formula in below form Let's try the mean formula, and you can then apply the same logic to variance and covariance. We have:

$$\mu_t=\left(1-\lambda\right)r_{t-1}+\lambda \mu_{t-1}$$

Which means:

$$\mu_{t-1}=\left(1-\lambda\right)r_{t-2}+\lambda \mu_{t-2}$$

$$\mu_{t-2}=\left(1-\lambda\right)r_{t-3}+\lambda \mu_{t-3}$$

Now we can take the first formula:

$$\mu_t=\left(1-\lambda\right)r_{t-1}+\lambda \mu_{t-1}$$

and substitute for $$\mu_{t-1}$$:

$$\mu_t=\left(1-\lambda\right)r_{t-1}+\lambda \left(1-\lambda\right)r_{t-2}+\lambda^2 \mu_{t-2}$$

Then substitute for $$\mu_{t-2}$$:

$$\mu_t=\left(1-\lambda\right)r_{t-1}+\lambda \left(1-\lambda\right)r_{t-2}+\lambda^2 \left(1-\lambda\right)r_{t-3}+\lambda^3 \mu_{t-3}$$

You can continue, but let's try a short cut. We can write the above using the summation:

$$\mu_t=\left(1-\lambda\right) \left(r_{t-1}+\lambda r_{t-2}+\lambda^2 r_{t-3} \right)+\lambda^3 \mu_{t-3}$$

$$\mu_t=\left(1-\lambda\right) \sum_{m=1}^3{\lambda^{m-1} r_{t-m}} +\lambda^3 \mu_{t-3}$$

Now we can replace 3 by M:

$$\mu_t=\left(1-\lambda\right) \sum_{m=1}^M{\lambda^{m-1} r_{t-m}} +\lambda^M \mu_{t-M}$$

We don't know the terms beyond M, so we discard the $$\mu_{t-M}$$ term, but then the weight won't sum to 1 - the sum of the weights would be $$1-\lambda^M$$ as you can easily verify. So if we divide by $$1-\lambda^M$$, the weights will sum to one:

$$\mu_t=\frac{1-\lambda}{1-\lambda^M} \sum_{m=1}^M{\lambda^{m-1} r_{t-m}}$$

And that's the formula for the mean. You can apply the same logic to variance and covariance.

re-comment, how the weights sum to $$1-\lambda^M$$, expand the summation:

$$S_w=\left(1-\lambda\right) \sum_{m=1}^M{\lambda^{m-1} }$$

$$S_w=\left(1-\lambda\right) \left(1+\lambda+\lambda^2+\dots+\lambda^{M-1} \right)$$

Multiply by $$\lambda$$

$$\lambda S_w=\left(1-\lambda\right) \left(\lambda+\lambda^2+\dots+\lambda^M \right)$$

and then subtract from the original, and simplify:

$$S_w-\lambda S_w=\left(1-\lambda\right)\left(1-\lambda^M \right)$$

$$S_w=\frac{\left(1-\lambda\right)\left(1-\lambda^M \right)}{1-\lambda}=1-\lambda^M$$

as desired.

• thanks very much for detail explaination, may I ask why the sum of weights would be 1-lambda^M? (another off-topic question, sorry, do u have any book recommendation for EWMA model?) – Shukman NG Oct 20 '19 at 3:22
• I have added the details around $1-\lambda^M$. Re-books, will check and get back to you! – Magic is in the chain Oct 20 '19 at 11:16
• I recommend Brown's book. It was written based on the original EWMA so doesn't add on all the bells and whistles that came along later which can possibly confuse someone who wants the basic underlying concept. It's called "smoothing, forecasting and prediction of discrete time series.". A real gem IMHO. – mark leeds Oct 20 '19 at 13:57
• @mark leeds, great recommendation! thanks – Magic is in the chain Oct 20 '19 at 19:26
• you're very welcome. get a used one on amazon. – mark leeds Oct 20 '19 at 20:32