I have 2 time series and I am using ccf
to find the cross correlation between them.
ccf(ts1, ts2)
lists the cross-correlations for all time lags. H
I thought I'd redo the above function but have it find the absolute max correlation that returns the original correlation (positive or negative). I also maxed out (nearly) the number of lags.
Find_Abs_Max_CCF<- function(a,b)
{
d <- ccf(a, b, plot = FALSE, lag.max = length(a)-5)
cor = d$acf[,,1]
abscor = abs(d$acf[,,1])
lag = d$lag[,,1]
res = data.frame(cor,lag)
absres = data.frame(abscor,lag)
absres_max = res[which.max(absres$abscor),]
return(absres_max)
}