Thursday, January 17, 2019

quant trading strategies - 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:


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?



Answer




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.


No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...