Select Page

# Rank Correlation in Technical Analysis

by | Feb 11, 2021 | Markets, Research, Technical Analysis

Rank correlation measures the “orderliness” of a price move.

In financial analysis, the term correlation generally refers to the Pearson correlation coefficient, which measures the linear correlation between two sets of data. There are other types of correlation, however, and one type in particular, the Spearman rank correlation, can serve as an excellent trend-detecting oscillator or overbought/oversold indicator in technical analysis.

### Introduction to Rank Correlation

Rank correlation measures the relationship between the ranks of the values of two data sets, while the Pearson correlation coefficient measures the relationship of the values of two data sets. To calculate the Spearman rank correlation between two data sets, simply convert each value to its rank in its data set, and then calculate the Pearson correlation coefficient of the two sets of ranks.

Consider the following two data sets:

1
6
11
-2
4
7
18
20
###### Data Set B
2
3
10
9
5
11
13
20

These data sets are shown in the scatterplot below. The Pearson correlation between the two data sets is 0.78.

Chart 1 – Scatterplot showing Data Set B vs Data Set A.

Now let’s add the ranks to the data sets.

For each value in a data set, the rank is where that value falls in the range of values in the data set. Before assigning ranks, the data can be sorted either ascending or descending. For example, using an ascending sort, the lowest value in a data set gets the rank of “1”, the next highest value gets a rank of “2”, and so on.

Refer to Data Set A shown above. Using an ascending sort, the smallest value in the data set is -2, so it gets a rank of “1”. The largest value is 20, so it gets a rank of “8”. If we instead used a descending sort, those values would be reversed and the value -1 would get a rank of “8” and the value 20 would get a rank of “1”.

For our purposes, we will always use an ascending sort. The next table shows the same data sets with the ranks included:

1
6
11
-2
4
7
18
20
2
4
6
1
3
5
7
8
2
3
10
9
5
11
13
20
###### Rank
1
2
5
4
3
6
7
8

The Spearman rank correlation between the two data sets is simply the Pearson correlation between the two sets of ranks. In this case, the rank correlation is 0.81, which is very close to the Pearson correlation of 0.78.

### Calculate Moving Rank Correlation for a Time Series

We can create a moving rank correlation indicator for a time series. This indicator has a single parameter which defines the lookback period.

For each th value in the time series:

1. Define a window of length that ends at .
2. Create a new times series that is an increasing sequence of integers from 1 to . Call this time series .
3. Convert all the time series values in the window to a series of ranks, using an ascending sort. Call this time series .
4. Calculate the Pearson correlation between and . This is the th value of the moving rank correlation indicator .

The table below illustrates this calculation for January 20, 2021 for May 2021 Crude Oil Futures.

1/4/21
1/5
1/6
1/7
1/8
1/11
1/12
1/13
1/14
1/15
1/19
1/20
1/21
1/22
47.51
49.91
50.56
50.96
52.71
52.20
53.29
52.90
53.75
52.13
53.03
52.96
53.03
51.98
1
2
3
4
5
6
7
8
9
1
4
3
8
5
9
2
7
6
###### R_R
0.47

May 2021 crude oil prices and calculation of moving rank correlation for 1/20/2021 with .

Chart 2 shows May 2021 Crude Oil futures including the moving rank correlation indicator with . The value calculated above for 1/20/2021 is highlighted.

Chart 2 – Moving Rank Correlation applied to crude oil prices, N = 9.

Cool – a wavy red histogram. But what does it mean?

Mathematically, measures the monotonicity of the price move in the window. From Wikipedia, a monotonic function is “a function between ordered sets that preserves or reverses the given order.” If the prices in the window are a purely monotonic function of time, that means they are either increasing in the window or decreasing in the window, but not some-of-one and some-of-the-other. If prices are stricly increasing, will have a value of 1.0, and when decreasing, a value of -1.0.

### An Orderly Price Move

On a more practical level, I think of this indicator as measuring the “orderliness” of a price move. What do I mean by orderliness? Orderliness is the tendency of prices to move in a single direction without a lot of backing-and-filling. In an orderly move, we don’t get “two steps forward and one step back.” Instead, we get three steps forward.

When this indicator is at a high level, it indicates prices have been moving up in a very orderly fashion. At a low level, it indicates prices have been moving down in an orderly fashion.

Note that the magnitude of the price changes do not matter. Whether prices move up by a tiny amount or a huge amount each day, this indicator will give the same reading. That’s why I think of it in terms of “orderliness” instead of “strength.”

### What Can It Do?

I have used this indicator on and off in my trading for years. A couple of features make it useful. First, even though there is no smoothing involved, the indicator seems to be naturally smoother than other similar indicators. Second, in spite of the smoothness, is relatively quick to signal a reversal.

Initially, I primarily used it as an OB/OS indicator and used it to generate counter-trend signals (coming down from an OB condition was a sell signal and coming out of OS was a buy signal). Used that way, however, it has the same problems as every other OB/OS indicator, namely that counter-trend signals in a strong trend are unreliable and tricky things to trade.

More recently, I use it for trend filtering. Typically, I use two different values of N to indicate whether or not a market is trending and which direction it is trending.

Summary

• Rank correlation is the correlation between the ranks of two data sets.
• Spearman rank correlation is the Pearson correlation coefficient of the ranks of two data sets.
• A moving rank correlation indicator of period can be calculated for a time series by calculating the Pearson correlation of:
• The ranks of the time series values in a backward-looking window, and
• An increasing set of integers from 1 to .