# Detecting leading stocks using lag correlation

I am working on a project to find leading stocks in a stock market by using lag correlation.

Say I want to compare 2 stocks, X and Y, and I have the time series of stock prices. Assume that the time series are equally spaced and homogeneous and their log returns are stationary (in my case I have raw tick data so it's unevenly spaced and contains many gaps but I have managed to preprocess the data to make them equally spaced and run tests for stationarity). Finding the maximum lag correlation of 2 stocks is straightforward; I can use ccf() in R to find the maximum lag correlation of their log returns and the corresponding time lag.

Find_Max_CCF <- function(a,b)
{
d <- ccf(a, b, plot = FALSE)
cor = d$$acf[,,1] lag = d$$lag[,,1]
res = data.frame(cor,lag)
res_max = res[which.max(res\$cor),]
return(res_max)
}

> Find_Max_CCF(as.ts(X_logreturns), as.ts(Y_logreturns))
cor  lag
0.1459474 1200


Here, the strongest correlation occurs at time (t-1200), indicating that Y is the lagging indicator (X is the leading indicator).

Now, the problem is when I have more than 2 stocks. Say I have 3 stocks, X, Y and Z, and I want to find which stock is the leading trend of the other ones. I've been looking into comparing multiple time series using lag correlations and it seems to me that there is no literature or discussion on this topic. So I came up with an idea and here's how I think: I can find the maximum lag correlation of log returns and the corresponding time lag for each pair of stocks, take two pairings with 1 stock in common, and compare them to find which stock is the top leading stock, second leading stock and so on.

For better illustration, look at the example below.

> Find_Max_CCF(as.ts(X_logreturns), as.ts(Y_logreturns))
cor  lag
0.1459474 1200
> Find_Max_CCF(as.ts(X_logreturns), as.ts(Z_logreturns))
cor  lag
0.1495813 -480
> Find_Max_CCF(as.ts(Y_logreturns), as.ts(Z_logreturns))
cor  lag
0.1935647 -360


In this case, we have the following pairs of relation: X succeeds Y, X precedes Z, and Y precedes Z. From the first two relations, we can see that if Z succeeds X, and if X succeeds Y, then it must be that Z is leading first, followed second by X, and lastly Y. This confirms the third relation that Y precedes Z (or Z succeeds Y).

Is it correct of me to think this way? Will my idea work for comparing multiple time series? Is it too naive? Is there a better way to do this? Any help will be greatly appreciated!