Logarithmic
Correlation Coefficient:
Measuring Quality of Trend Lines
By Mark P Martin,
Emporium Software
Various
traders and market analysts state that the slope or steepness of a trend line is
an indication of the quality of the trend. John Murphy writes that "...most
important up trend lines tend to approximate an average slope of 45
degrees." Gann studies try to
scale the chart in such a way that an "ideal" trend line would have a
1 x 1, or a 45 degree slope. Steven
B. Achelis writes of Gann studies in Technical
Analysis from A to Z,
"W.
D. Gann (1878-1955) designed several unique techniques for studying price
charts. Central to Gann's techniques was geometric angles in conjunction with
time and price. Gann believed that specific geometric patterns and angles had
unique characteristics that could be used to predict price action.
“All
of Gann's techniques require that equal time and price intervals be used on
the charts, so that a rise/run of 1 x 1 will always equal a 45 degree angle.
“Gann
believed that the ideal balance between time and price exists when prices rise
or fall at a 45 degree angle relative to the time axis. This is also called a
1 x 1 angle (i.e., prices rise one price unit for each time unit).”
First,
with regard to the 45-degree angle discussion, consider a hypothetical example
with some extremes to illustrate a point. Suppose some stock goes from 101
to 102 over a five-year period, and the stock has very smooth, consistent
movements (albeit very small) with very little variation away from the trend
line. One could construct a chart with 101 at the bottom of the Y-axis and
102 at the top, with 10 increments of 0.10 point each, and five years divided up
into 10 increments of 6-months each on the X-axis. If the chart were
perfectly square, then the chart would rise steadily from the lower left-hand
corner to the upper right-hand corner, and if the daily (or weekly, or whatever)
price changes were consistent, then the chart would form a nice straight
45-degree angle. According to Gann theory, this would be a good
high-quality trend line. Gann theory goes on to describe how once the
chart falls off of a trend line, it finds support/resistance levels at another
trend line that is defined by a different ratio, say 1 x 2 or 1 x 3, or 2 x 1 or
some integral ratio. If you don't use a square chart (even if you use
square increments), or if you don't fully scale the axes to the minimum and
maximum values, or if you leave an empty buffer zone at the right or at the
bottom, then the idea of an ideal 45-degree angle breaks down.
I
propose that the scaling if the chart is irrelevant, that the "45-degree
rule" is constructed for visual inspection on this ideal square chart.
On the other hand, mathematicians and statisticians have already devised a means
of measuring the quality of the relationship of one variable (price, in this
case) to another (time). That measure is the correlation coefficient.
Correlation coefficient has been in use since before W.D. Gann was charting
stocks. Karl Pearson published a paper on statistics describing
correlation in 1895. The formula for correlation coefficient is available in
virtually all spreadsheets and most charting packages, and it's in any
statistics text.
The
formula for the Pearson product-moment correlation coefficient (r) of X to Y
over N (X, Y) value-pairs is:
The
value of r ranges from -1.0 to +1.0. A value close to +1.0 indicates a
good positive correlation with positive slope; a value close to -1.0 indicates a
good negative correlation with negative slope; a value close to 0 indicates a
poor correlation with no definable slope.
To
use this to measure the quality of trend of a stock, use the closing price (C)
for Y, and the date for X. Most software will translate the date in
calculation to the "Julian date", which is the number of days that
have passed since the calendar began. Since Julian date values can be in
the millions, these values will break the formula for any 32-bit software doing
integer math. Nearly all home computers are 32-bit. If using the
(Julian) date for the X values doesn't work, then find the number of days for
each price point since the beginning of the chart by subtracting the first date
from each of the remaining dates. Again, most software internally converts
dates to Julian date values before doing the calculation. A slightly less
accurate way to get the X values is to create an incremental cumulative sum of 1
(or some other fixed increment) for each price point. This is less
accurate because it doesn't account for weekends and holidays, or overnight
hours in the case of an intra-day chart. But since the use of correlation
coefficient is usually relative, if you use the same method consistently, the
inaccuracies will not be noticeable.
The
previous discussion assumes that price movement is modeled on a linear curve.
In financial markets, this is not the case. Financial markets are best
modeled with an exponential formula. In the case of a fixed-rate
money-market account that is compounded daily at rate R, the formula for any
future value at time t is:
If R is an annual interest rate, then you have to further annualize the rate:
where t is in days.
Anyway, Principle P is an exponential
function of time, t. The same model applies to stock prices. If you
look at a 100-year chart of the DJIA, you will see that it changes much more in
recent years than in the earlier years.
To properly view such a chart, the Y-axis should be on a logarithmic
scale, where you will see increments from 10 to 100, to 1000, etc., and various
logarithmic increments in-between. When plotted on this scale, the
100-year DJIA will appear more like a straight line than the
"hockey-stick" curve on a linear chart.
Examine
a
chart of the NASDAQ from Jan. 1991 through Mar. 2000. On a linear chart,
it's a hockey-stick curve, but on a logarithmic scale, it's more of a
straight-line. A similar effect can be obtained by plotting the logarithm
of the price on a linear chart. The logarithm of NASDAQ from 1/1991 to
3/2000 on a linear
chart is a close to a linear curve.
To
apply the exponential nature of the price chart to the correlation calculation,
you need only to take the logarithm of the prices (the Y value) before
performing the correlation calculation. It doesn't matter whether you use
a natural or a base-10 logarithm, because the correlation formula looks at the
differences in values relative to the corresponding X values. Either log will
produce the exact same correlation value. I've computed a 9-year (2250
day) correlation coefficient of the NASDAQ at the top of the bull market, on
3/27/2000.
Using linear prices, r = 0.857
Using logarithmic prices, r = 0.968
The correlation for the exponential model (logarithmic prices) is greater than
for the linear model, which shows that the exponential model is a better fit for
the data given. Although the difference in correlation values will be less
on a smaller time-scale, this demonstrates that the exponential model is more
appropriate for correlation analysis as well as for linear regressions,
volatility, and most other statistical calculations.
In
practice, this particular use of correlation is similar to many other
quality-of-trend indicators. Use it as a filter for entry (and optionally
for exit) rules. Only enter a trade when correlation is at some relatively
high value. The value of correlation that would indicate a significant
trend would be subject to some experimentation. In pure statistical
analysis, the significance of correlation is determined by another complicated
formula, which is usually listed in tables of values in the appendix of
statistics texts. For example, with 100 data points, there is a 99 percent
confidence level in a correlation of 0.2540. This means that with 100 data
points, if the correlation were 0.2540, there would be a 1% chance that the
relationship is due to randomness instead of an actual relationship. In
practice, any correlation that is greater than 0.95 could be thought of as a
reliable relationship or trend. I also like to apply correlation analysis
to the equity curve of trading system backtests. Again, I use an exponential
model by taking the logarithm of the daily equity values before doing a
correlation. It's been my experience that even with short time periods, if
the growth that the system produces is extreme, it's always exponential in
nature, and a logarithmic correlation and a logarithmic linear regression is
more accurate. When optimizing a system, I often use a logarithmic
linear-regression slope, although lately I've been considering the possibilities
of maximizing logarithmic correlation coefficient. One of the users of Pikker
has written a system that in backtesting over the past five years has an equity
correlation of 0.98. That system also has exponential growth, and a very
high-quality equity curve on a logarithmic scale.
A MS
Word formatted copy of this article can be downloaded here.
Copyright © 2003, Mark P Martin, mark@emporium-sw.com
Emporium Software, http://www.emporium-sw.com
This article may be reproduced and distributed in full if this copyright
notice is included.
|