# What is the difference between a moving average crossover and a moving average of returns?

In Python:

import pandas as pd
# z is a pd.Series of prices

# Moving average crossover
z.ewm(span=24).mean() - z.ewm(span=96).mean()

# Moving average of returns
z.diff().ewm(span=96).mean()


What is the difference:

• Mathematically
• Qualitatively

I believe the latter is simpler, and has the advantage of having only one parameter to configure. What's the issue with it?

• What python package are you using? Sep 21 '18 at 11:40
• pandas (added to question) Sep 21 '18 at 11:43
• They are not the same. $\frac{1}{24} \sum_{i=0}^{23} p_{t-i}-\frac{1}{96} \sum_{i=0}^{95} p_{t-i}\neq\frac{1}{96}\sum_{i=0}^{95}(p_{t-i}-p_{t-i-1})$. The weights on the p's are different. BTW in the second case it is a moving average of price differences (not returns). Sep 21 '18 at 13:33

Moving averages of prices are closely related to moving averages of price differences. In particular, if the price is a cumulative sum of historical price differences,

$$p_t = \sum_{j=0} \delta p_{t-j}$$

then a moving average of prices with weights $$w_k$$ can be written as a moving average of price differences with weights $$v_k$$

$$\sum_{k=0}w_k p_{t-k} = \sum_{k=0} w_k \sum_{j=0}\delta p_{t-j-k} = \sum_{k=0} \left(\sum_{i=0}^k w_i\right) \delta p_{t-k} = \sum_{k=0} v_k \delta p_{t-k}$$

where

$$v_k = \sum_{i=0}^k w_i$$

In particular, a moving average crossover with spans $$(n_1, n_2)$$ is a moving average of prices, where

$$w_k = \begin{cases} 1/n_1 - 1/n_2 & \text{if } k < n_1 \\ -1/n_2 & \text{if } n_1 \leq k < n_2 \\ 0 & \text{otherwise} \end{cases}$$

It is therefore also a moving average of price differences. It differs from the simple moving average, which has equal weight on all lags, by having very little weight on the first lag, with weights linearly increasing up to lag $$n_1$$, and then linearly decreasing up to lag $$n_2$$.

Qualitatively, the moving average crossover filters out more of the higher frequency noise resulting in a 'smoother' signal (intuitively this is because there is very little weight on either the most recent or most distant observation). In the language of signal processing it is a form of low pass filter. There is a tradeoff of smoothness of the resulting signal against reactivity to recent price changes.

• This is actually a brilliant answer. Thank you so much!!! :) Sep 21 '18 at 15:18
• I second that motion regarding a brilliant answer. Below is is a link to paper that goes into similar arguments that chris taylor gave. Highly recommended. papers.ssrn.com/sol3/papers.cfm?abstract_id=2604942 Sep 21 '18 at 23:06