Skip to content
All library documents

Finite-Window Exponential Moving Averages and Half-Life Cutoffs

Article Quant Q&A · Author: user1953907

Summary

The document considers how to compute an exponential moving average across a large universe without replaying every observation since each security began trading. It explains that the recursive form needs only the prior EMA, while the equivalent direct form weights past observations by powers of a smoothing factor. Since an infinite history is unavailable, the direct calculation requires a practical cutoff; the decay factor’s half-life offers a way to judge how far back to include data.

A second approach constructs normalized weights over a finite sample by dividing exponential weights by their finite sum, then takes their weighted average. This keeps the included weights summing to one without using older data to initialize the estimate. The document presents this as an unbiased finite-window estimate, but gives no comparative tests or error bounds. The result depends on the chosen window and decay parameter, and finite-window weighting differs from an EMA that retains all historical influence.

Key ideas

  • The recursive EMA update requires only the previous EMA value and the latest observation.
  • A direct weighted sum uses exponentially decaying weights on past observations.
  • The smoothing factor’s half-life can guide the choice of a finite lookback window.
  • Normalizing exponential weights over the chosen window makes their sum equal one without older initialization data.
  • A finite window changes the estimator by excluding the influence of observations before the cutoff.

Tags

Full text
# Is there a non-recursive way of calculating the exponential moving average?


# Is there a non-recursive way of calculating the exponential moving average?












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:

$EMA_n = p_n\frac{2}{T+1}+EMA_{n-1}\left(1-\frac{2}{T+1}\right)$

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?

## Answer by David Addison (score 6, accepted)

https://quant.stackexchange.com/a/33635

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.

## Answer by msitt (score 7)

https://quant.stackexchange.com/a/33549

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.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.