0
$\begingroup$

In finance, many "indicators" are used in order to make prediction about if a price has an increasing or decreasing trend over time.
Among them, MACD is a popular one. There are many slighlty different definitions (standard rolling mean vs. exponential rolling mean, etc.), but one of them is :

  • the price is $x[n]$ (let's say the sampling rate is 1 second, but we could also use 1 day...)

  • $y_1[n]$ is the 12-period rolling mean, $y_2[n]$ is the 26-period rolling mean, i.e. :

$$y_1[n] = \frac{1}{12} x[n] + \frac{1}{12} x[n-1] + ... + \frac{1}{12} x[n-11]$$ and the same for $y_2$.

  • the MACD is defined by $y_1 - y2$, i.e. :

$$macd[n] = \frac{7}{156} x[n] + \frac{7}{156} x[n-1] + ... + \frac{7}{156} x[n-11] - \frac{1}{26} x[n-12] - \frac{1}{26} x[n-13] + ... - \frac{1}{26} x[n-25]$$

Question:

How to have a signal processing interpretation of what's going on with $macd[n]$? I can see it's a linear filter, but how to know what it is doing? Can we draw a frequency response? It also seems that, because of rolling mean, some lag / delay is introduced.


Remark: When people use MACD, they don't stop with $macd[n]$: they define $signal[n]$ as the 9-period rolling mean of $macd[n]$:

$$signal[n] = \frac{1}{9} macd[n] + \frac{1}{9} macd[n-1] + ... + \frac{1}{9} macd[n-8]$$

and the indicator which is finally used is (this sounds like a magic trick! why these choices?):

$$h[n] = macd[n] - signal[n] = -\frac{14}{351}x[n]-\frac{49}{1404} x[n-1]-\frac{7}{234} x[n-2]-\frac{35}{1404} x[n-3]-\frac{7}{351} x[n-4]-\frac{7}{468} x[n-5]-\frac{7}{702} x[n-6]-\frac{7}{1404} x[n-7]+\frac{2}{27} x[n-12]+\frac{7}{108} x[n-13]+\frac{1}{18} x[n-14]+\frac{5}{108} x[n-15]+\frac{1}{27}x[n-16]+\frac{1}{36}x[n-17]+\frac{1}{54}x[n-18]+\frac{1}{108}x[n-19]-\frac{4}{117}x[n-26]-\frac{7}{234}x[n-27]-\frac{1}{39}x[n-28]-\frac{5}{234}x[n-29]-\frac{2}{117}x[n-30]-\frac{1}{78}x[n-31]-\frac{1}{117}x[n-32]-\frac{1}{234}x[n-33]$$

When $h[n]$ is positive the trend of $x[n]$ is more or less increasing, and when $h[n]$ is negative, the trend of $x[n]$ is more or less decreasing.

Question:

What does $h[n]$ do, with a DSP point of view?

$\endgroup$
  • $\begingroup$ There are many articles about using the MACD, among them: investopedia.com/articles/technical/082701.asp $\endgroup$ – user14819 Dec 25 '15 at 23:56
  • $\begingroup$ @user14819 I know this, but my question is about having a "DSP interpretation" of what's going on... $\endgroup$ – Basj Dec 26 '15 at 9:10
3
$\begingroup$

I thought you stock market tech analysts always used moving averages (rolling means) or "exponential moving averagers" for your smoothing operations. Anyway, your $macd[n]$ process is neither of those. As far as I can tell the frequency magnitude response of your $macd[n]$ process looks like the following:

enter image description here

Your $macd[n]$ process does not smooth its input data in the normal sense. It amplifies input data that has a periodicity (repetition rate) of 33.3 days per cycle. In the above plot you can clearly see the "mainlobe" that Fat32 was referring to. If your closing price data contains a periodicity of roughly 33 days then the output of your $macd[n]$ process will be a large value. Otherwise, the output of your $macd[n]$ process will be a small value. I don't know if such a frequency response makes stock market technical analysis sense, or not.

As for your $h[n]$ process, I believe its frequency magnitude response looks like the following:

enter image description here

Your $h[n]$ process appears to be a process that amplifies input data that has a periodicity (repetition rate) of 21.9 days per cycle. In DSP we use processes like your $macd[n]$ and $h[n]$ for filtering when we want to detect the presence of components in our input signal that have periodicities of 33.3 or 21.9 time units per repetition. We call such processes "resonators" or "bandpass filters."

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thanks! How did you get this frequency response from the coefficients which I provided, and the graph? (if possible, could you paste the code?) $\endgroup$ – Basj Dec 25 '15 at 19:54
  • $\begingroup$ Do you understand here (i don't) : en.wikipedia.org/wiki/MACD#Mathematical_interpretation ? $\endgroup$ – Basj Dec 25 '15 at 19:57
  • $\begingroup$ You make the assumption that this wikipedia interpretation is correct and understandable. $\endgroup$ – hotpaw2 Dec 25 '15 at 21:46
  • 1
    $\begingroup$ The only correction I would make is that h[n] detects or amplifies pure sinusoidal components of 21.9 days, not periodicities or repetition rates. A pure periodicity of 21.9 days could contain only harmonics of 21.9 days, and thus never be detected by the h[n] filter process (above the filter's noise floor). $\endgroup$ – hotpaw2 Dec 25 '15 at 21:52
  • $\begingroup$ Just a simpler question: given a signal $x[n]$, how to compute and plot the freq response of the filters $out1[n] = x[n]- x[n-1]$ or $out2[n] = x[n]-2\ x[n-1]+x[n-2]$? $\endgroup$ – Basj Dec 25 '15 at 22:07

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.