The cross-correlation function measures correlation between two series at lags −lagMax..+lagMax, with ±1.96/√n significance bounds.
CCF generalises the autocorrelation function (ACF) to two series. CCF(k) = corr(xₜ, yₜ₊ₖ); a peak at positive k means x leads y by k periods, negative k means y leads x.
Pre-whiten first: spurious lead-lag relationships are easy to find between two series that share a trend or strong autocorrelation. Fit an ARIMA to one series, apply the same filter to the other, then compute the CCF of the residuals.
Two numeric series + max lag.
ECharts bar chart with bars outside ±1.96/√n band coloured red + peak |CCF| + its lag. Positive lag = first series leads.
Without pre-whitening, the CCF is dominated by the autocorrelation in each series. A clean lead-lag spike usually requires residuals of an ARIMA fit on each side.