Solved – Detecting trend reversal in a time series

structural-changetime seriestrend

I'm a novice in time series analysis and I'm trying to detect trend reversals automatically. In the example below, a heuristic rule would say that a trend reversal has occurred if the value has been trending in a direction for t1 seconds, then in the other direction for t2 = t1/k seconds.

Trend reversal example

I've tried to parse the answer on detecting trends but it went beyond my head. While I know I need to read up way more on time series analysis, I wonder if there are simpler (and more coarse) methods for detecting trends and trend reversals. Something like detecting slopes and calculating the angle between them?

Best Answer

With realistically noisy signals, this is not a simple problem. For example, you write

a heuristic rule would say that a trend reversal has occurred if the value has been trending in a direction for $t1$ seconds, then in the other direction for $t2 = t1/k$ seconds.

What if the signal would rise for $t1$ seconds by a total of $5\%$, then fall for $t1 / k$ seconds by a total of $6\%$, except for some time point in the second part where it rises by a negligible $0.0000001\%$?

A refinement on your idea would be to spot some difference between some types of moving averages between two time intervals. The moving averages would (hopefully) smooth out these problems, and the difference would be more indicative of a trend change.

In econometric technical analysis, one implementation of this is through the MACD (moving average convergence divergence).

The idea is

  1. take a "slow" exponential moving average (in the original context, 26 days)

  2. take a "fast" exponential moving average (in the original context, 12 days)

  3. subtract the former from the latter

  4. take an exponential moving average of 3. (in the original context, 9 days)

When the difference between 3. and 4. crosses 0, it's an indication that the trend reverse.

You can see an example in the following diagram (taken from the Wikipedia entry).

enter image description here

In the top diagram, the red/green lines indicate the market price. The purple and black lines indicate the fast and slow moving averages.

In the bottom diagram, the blue line is 3., and the red line is 4. The difference between them is the grey bar chart.

You can see that a zero crossing of the grey bar chart, roughly corresponds to a trend change in the original green/red prices.