statsmodels.tsa.stattools.ccf

statsmodels.tsa.stattools.ccf(x, y, adjusted=True, fft=True, *, nlags=None, alpha=None)[source]

The cross-correlation function.

Parameters:
x : array_like

The time series data to use in the calculation.

y : array_like

The time series data to use in the calculation.

adjusted : bool

If True, then denominators for cross-correlation are n-k, otherwise n.

fft : bool, default True

If True, use FFT convolution. This method should be preferred for long time series.

nlags : int, optional

Number of lags to return cross-correlations for. If not provided, the number of lags equals len(x).

alpha : float, optional

If a number is given, the confidence intervals for the given level are returned. For instance if alpha=.05, 95 % confidence intervals are returned where the standard deviation is computed according to 1/sqrt(len(x)).

Returns:

  • ndarray – The cross-correlation function of x and y: the element at index k is the correlation between {x[k], x[k+1], …, x[n]} and {y[0], y[1], …, y[m-k]}, where n and m are the lengths of x and y, respectively.

  • confint (ndarray, optional) – Confidence intervals for the CCF at lags 0, 1, …, nlags-1 using the level given by alpha and the standard deviation calculated as 1/sqrt(len(x)) [1]. Shape (nlags, 2). Returned if alpha is not None.

Notes

If adjusted is True, the denominator for the cross-correlation is adjusted.

References