TrendSpotting 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 trendspotting 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 microtrend upward. The second case is two successive decreases, so a downward microtrend. The third and fourth cases show no trend, but instead are interpreted here as small portions of cycles, or microcycles.
Figure 1. The four possible arrangements of three successive stock prices.
If values P_{1}, P_{2} and P_{3} are assigned to the three consecutive prices then, in the first case, P_{2} > P_{1} and P_{3} > P_{2}, while in the third case P_{2} > P_{1} but P_{3} < P_{2}. 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 D_{1} = P_{2} – P_{1} and D_{2} = P_{3} – P_{2}. Then, for the first two trend cases, the product D_{1}*D_{2} > 0, while for the cycle cases D_{1}*D_{2} < 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 microtrend.
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(k1).
Next, define a new series a(k) as the product of consecutive increments, i.e.,
a(k) = z(k) z(k1).
Then if a(k) is positive, the series x(k) is in a microtrend on day k and, conversely, a negative a(k) indicates a microcycle.
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 (oneday) autocorrelation 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), sonamed 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 anticorrelation 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 largevalued 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 22day 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 7day trend that ends with a cycle indicated by a negative atom at day 14. The subsequent 3day downtrend 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 22day 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 21day average in our Kalman Filter predictor; predictions are ignored if the average of the increment atoms falls below a specified level.
Ehlers, J & Way, R, “Fractal Dimension As A Market Mode Sensor”, TASC, June 2010.
Martinelli, R, “Pattern Recognition In TimeSeries”, 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 
=B4B3 

5 
39899 
9.49 
=B5B4 
=C5*C4 
6 
39902 
8.8625 
=B6B5 
=C6*C5 
7 
39903 
9.0425 
=B7B6 
=C7*C6 
8 
39904 
8.7925 
=B8B7 
=C8*C7 
9 
39905 
9.4925 
=B9B8 
=C9*C8 
10 
39906 
9.825 
=B10B9 
=C10*C9 
11 
39909 
10.265 
=B11B10 
=C11*C10 
12 
39910 
10.195 
=B12B11 
=C12*C11 
13 
39911 
10.54 
=B13B12 
=C13*C12 
14 
39912 
11.1225 
=B14B13 
=C14*C13 
15 
39916 
11.58 
=B15B14 
=C15*C14 
16 
39917 
11.7625 
=B16B15 
=C16*C15 
17 
39918 
12.2975 
=B17B16 
=C17*C16 
18 
39919 
13.7375 
=B18B17 
=C18*C17 
19 
39920 
15.215 
=B19B18 
=C19*C18 
20 
39923 
14.605 
=B20B19 
=C20*C19 
21 
39924 
14.2675 
=B21B20 
=C21*C20 
22 
39925 
14.1475 
=B22B21 
=C22*C21 
23 
39926 
14.065 
=B23B22 
=C23*C22 
24 
39927 
14.655 
=B24B23 
=C24*C23 
25 
39930 
15.1025 
=B25B24 
=C25*C24 
26 
39931 
15.8925 
=B26B25 
=C26*C25 
27 
39932 
17.9825 
=B27B26 
=C27*C26 