5
$\begingroup$

I want to calculate the exponential moving average for many stocks in a large investable universe. To do this, I've seen the following formula:

exponential moving average recursive formula

Because it references the previous day's exponential moving average, it seems to me like I would need to calculate the exponential moving average for every day going back to the security's inception in order to get an accurate ema for today. This seems like it would require too many computations to be used effectively. Is there a way to calculate an accurate ema that is less computationally heavy?

$\endgroup$
  • $\begingroup$ I see you haven't accepted an answer. What further information do you need in order to accept an answer? $\endgroup$ – David Addison Apr 25 '17 at 18:50
5
$\begingroup$

I've been waiting for someone to ask this question since every published method with which I am familiar propose weights which converge to $1$ only when the numbers of terms goes to infininity. This is quite annoying as it either requires we use a biased estimate which underestimates the true exponentially weighted mean or use back-dated information to parameter-ize the initial value.

Suppose you have weighting factors in which lagged weights are a factor of $\beta$, where:

$$\beta= e^{\frac{-\Delta t}{\tau}}$$

(note: $\beta[t]$ is the canonical weighting vector of an exponential moving average)

To come up weights, we want to find a series such that:

$${\Sigma}_{t=0}^{T=N}( \frac{\beta^{T-t}}{\Sigma\beta^{\Delta t}}) = 1$$

The sum of the raw exponential weights can be found through a series expansion:

$$\Sigma_{t=0}^{T=N} \beta^{\Delta t} = \frac{1-\beta^T}{1-\beta}$$

Therefore, periodic weights, $\omega_i$ can found as follows:

$$\omega_i = {\Sigma}_{t=0}^{T=N}\frac{\beta^{T-t}(1-\beta)}{1-\beta^T}$$.

If we have a vector of values:

$$X_i = [X_1,\, X_2, \, ...X_N]$$

and a vector of weights:

$$\omega_i = [\omega_1,\, \omega_2, \, ...\omega_N]$$

the dot-product of the two vectors will provide an unbiased estimate of the exponentially weighted average where the sum of weights always equal $1$ and where no out-of-sample terms are required to parameterize the initial value. The recursion is limited only to a finite series the same size as the data to be weighted.

$$\text{EWMA} = f(\omega_i \cdot X_i)= \Sigma (\omega_i * X_i)$$

Please let me if/how this works for you.

$\endgroup$
5
$\begingroup$

The point of the recursive formula is that you can easily calculate the current EWMA if you have last period's EWMA.

Equivalently, you can calculate all the weights directly and sum them that way. $$ \text{EWMA}_t = S_t(1-\lambda) + S_{t-1}(1-\lambda)\lambda + S_{t-2}(1-\lambda)\lambda^2 + \dots $$ where $\lambda$ is your smoothing parameter between $0$ and $1$. Higher values indicate a smoother average while lower values put more weight on the recent observations. In relation to your post, $$ 1-\lambda=\frac{2}{T+1}. $$

You probably notice both of these formulations require you to go back infinitely far to get the current EWMA. Of course we can't do that, so the question now becomes where can you cut it off?

The advantage of the 2nd formulation is that you can derive the half life $\tau$ as $$ \lambda^\tau=\frac{1}{2} $$ or $$ \tau = \log_\lambda(1/2)=\frac{\ln(1/2)}{\ln(\lambda)} $$ This gives you some practical guidance on how many steps you really need to go back to get a good estimate.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.