Trend-Spotting in the Stock Market

by Rick Martinelli, Haiku Laboratories

 

(Note: This article appeared in the 2011 Special Issue of Technical Analysis of Stocks and Commodities.)

 

Trends And Cycles

The vast majority of stock market data can be thought of as combinations of “trends” of various lengths and direction, and “cycles” of various frequencies and durations.  Consequently, many techniques have been developed to discern when a particular stock is trending or cycling.  The current article describes a simple approach to trend-spotting that is based on the idea that correlations in price differences translate into trends in prices. 

 

To see this, consider exactly what constitutes a trend at the smallest level.  Assuming the minimum number of consecutive prices required to spot a trend is three, there are four possible arrangements of three prices, as shown in Figure 1.  In the first case, prices show two successive increases and are in a short upward trend, a micro-trend upward.  The second case is two successive decreases, so a downward micro-trend.  The third and fourth cases show no trend, but instead are interpreted here as small portions of cycles, or micro-cycles.  

 

   

Figure 1. The four possible arrangements of three successive stock prices.

 

If values P1, P2 and P3 are assigned to the three consecutive prices then, in the first case, P2 > P1 and P3 > P2, while in the third case P2 > P1 but P3 < P2.  The other two cases may be similarly characterized by their corresponding price inequalities.  But all of this information may be summarized by instead considering the price increments D1 = P2 – P1 and D2 = P3 – P2.  Then, for the first two trend cases, the product D1*D2 > 0, while for the cycle cases D1*D2 < 0, that is, the product of increments is positive for a trend!  In addition, the value of the product gives a rough indication of the amount of price movement in the three points, the intensity of the micro-trend.

 

Trends And Correlations

Now consider a series of daily stock prices represented by x(k) for k = 1 to N, where N is the total number of days.  Its series of price changes, known as its increment series is

 

                                                                         z(k) = x(k) – x(k-1).   

 

Next, define a new series a(k) as the product of consecutive increments, i.e.,

 

                                                                          a(k) = z(k) z(k-1).

 

Then if a(k) is positive, the series x(k) is in a micro-trend on day k and, conversely, a negative a(k) indicates a micro-cycle. 

 

Any series of increments z(k) has an average M and standard deviation S.  If the original series z(k) is replaced everywhere with (z(k) – M)/S, then the resulting series has mean zero, variance one, and is said to be normalized.  For a normalized series, the (one-day) auto-correlation coefficient , defined by

 

                                                                      ,

 

is a statistic indicating the similarity between itself and a version of itself shifted back in time by one day.  But it turns out that this is also the AC for the series z(k) before it was normalized, so that the AC for the original increment series is just the average of our a(k)’s:

 

                                                                           .

 

This is the connection between correlations in the increments and trends in the data.  The a(k)’s are called the correlation atoms of the series z(k), so-named because they constitute the smallest possible pieces of correlation in z.  The AC takes values between -1 and +1, where +1 indicates complete correlation, -1 indicates complete anti-correlation and AC = 0 means no correlation at all. 

 

An Example

The result above suggests that stocks with a large, positive AC should contain more trends than other stocks. So, on 03/24/10, a large database of stocks was scanned and sorted by their AC’s.  At the top of the list was WHI with a coefficient of AC = 0.501.  Figure 2 shows one year of the average price of WHI, ending 03/24/10, where the average is over the daily open, high, low and closing prices.  Figure 3 shows the corresponding correlation atoms for WHI, where the overall ratio of positive atoms to total is 0.628, indicating almost twice as much trending as cycling during the year, in agreement with its large AC value.  

 

Figure 2. Average of open, high, low and close for WHI.

 

Figure 3.  Correlation atoms for WHI.

 

Rapid price increases seen during May and December in Figure 2 are seen as a scattering of large-valued atoms in Figure 3, in contrast with the middle section from July to November which has much smaller values distributed around zero.  In Figure 4, prices and atoms (red dots) are shown graphed together for the December data, a 22-day period ending December 29.  From the atoms we can read off the behavior of the data.  The positive atom at point 7 indicates the start of a 7-day trend that ends with a cycle indicated by a negative atom at day 14.  The subsequent 3-day down-trend is accompanied by three positive atoms and ends with a cycle indicated by the negative atom on day 18.  Another uptrend begins after that. 

 

Figure 4. A 22-day portion of WHI prices ending December 29 and their corresponding correlation atoms (red dots).

 

Other Uses

We’ve seen that correlation atoms are effective indicators of trends and cycles at the smallest level.  To find longer trends, a moving average may be applied to the atoms yielding a smoother, yet still responsive indicator.  Or, a watch may be set for two or more consecutive, positive atoms.  The atoms may even be useful to cycle traders:  longer cycles may be detected as several consecutive positive atoms interrupted at regular intervals by one or more negative atoms, similar to the behavior in the latter part of Figure 4.  In addition to finding trends, the atoms and/or their averages may be used in prediction schemes.  We have successfully employed a 21-day average in our Kalman Filter predictor; predictions are ignored if the average of the increment atoms falls below a specified level.     

 

Readings

Ehlers, J & Way, R, “Fractal Dimension As A Market Mode Sensor”, TASC, June 2010.

Martinelli, R, “Pattern Recognition In Time-Series”, TASC, January 1998.

Rhoads, N & Martinelli, R, “Predicting Market Data Using The Kalman Filter” , TASC, January 2010.

 

 


Sidebar

A simple Excel spreadsheet may be used to calculate the correlation atoms of any set of prices.  Shown here are the formulas and actual numbers used to produce the charts here (only the first 25 of the 252 records are shown).  Column B contains the averaged prices,  column C the increment values and the atoms are in column D.

 

 

A

B

C

D

 

Date

Average Price

Increments

Atoms

3

03/25/09

9.47

 

 

4

03/26/09

9.67

0.198

 

5

03/27/09

9.49

-0.178

-0.035

6

03/30/09

8.86

-0.628

0.111

7

03/31/09

9.04

0.180

-0.113

8

04/01/09

8.79

-0.250

-0.045

9

04/02/09

9.49

0.700

-0.175

10

04/03/09

9.83

0.333

0.233

11

04/06/09

10.27

0.440

0.146

12

04/07/09

10.20

-0.070

-0.031

13

04/08/09

10.54

0.345

-0.024

14

04/09/09

11.12

0.583

0.201

15

04/13/09

11.58

0.458

0.266

16

04/14/09

11.76

0.182

0.083

17

04/15/09

12.30

0.535

0.098

18

04/16/09

13.74

1.440

0.770

19

04/17/09

15.22

1.478

2.128

20

04/20/09

14.61

-0.610

-0.901

21

04/21/09

14.27

-0.338

0.206

22

04/22/09

14.15

-0.120

0.040

23

04/23/09

14.07

-0.083

0.010

24

04/24/09

14.66

0.590

-0.049

25

04/27/09

15.10

0.448

0.264

26

04/28/09

15.89

0.790

0.354

27

04/29/09

17.98

2.090

1.651

 


 

 

 

A

B

C

D

 

Date

Average Price

Increments

Atoms

3

39897

9.47

 

 

4

39898

9.6675

=B4-B3

 

5

39899

9.49

=B5-B4

=C5*C4

6

39902

8.8625

=B6-B5

=C6*C5

7

39903

9.0425

=B7-B6

=C7*C6

8

39904

8.7925

=B8-B7

=C8*C7

9

39905

9.4925

=B9-B8

=C9*C8

10

39906

9.825

=B10-B9

=C10*C9

11

39909

10.265

=B11-B10

=C11*C10

12

39910

10.195

=B12-B11

=C12*C11

13

39911

10.54

=B13-B12

=C13*C12

14

39912

11.1225

=B14-B13

=C14*C13

15

39916

11.58

=B15-B14

=C15*C14

16

39917

11.7625

=B16-B15

=C16*C15

17

39918

12.2975

=B17-B16

=C17*C16

18

39919

13.7375

=B18-B17

=C18*C17

19

39920

15.215

=B19-B18

=C19*C18

20

39923

14.605

=B20-B19

=C20*C19

21

39924

14.2675

=B21-B20

=C21*C20

22

39925

14.1475

=B22-B21

=C22*C21

23

39926

14.065

=B23-B22

=C23*C22

24

39927

14.655

=B24-B23

=C24*C23

25

39930

15.1025

=B25-B24

=C25*C24

26

39931

15.8925

=B26-B25

=C26*C25

27

39932

17.9825

=B27-B26

=C27*C26