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

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?

  • $\begingroup$ What python package are you using? $\endgroup$
    – amdopt
    Commented Sep 21, 2018 at 11:40
  • $\begingroup$ pandas (added to question) $\endgroup$
    – cjm2671
    Commented Sep 21, 2018 at 11:43
  • 1
    $\begingroup$ 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). $\endgroup$
    – nbbo2
    Commented Sep 21, 2018 at 13:33

1 Answer 1


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} $$


$$ 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.

  • $\begingroup$ This is actually a brilliant answer. Thank you so much!!! :) $\endgroup$
    – cjm2671
    Commented Sep 21, 2018 at 15:18
  • 1
    $\begingroup$ 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 $\endgroup$
    – mark leeds
    Commented Sep 21, 2018 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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