CCOVF
This function computes the cross-covariance function between two univariate series, quantifying linear co-movement across lag offsets.
For lag k, the cross-covariance is:
\gamma_{xy}(k) = \operatorname{Cov}(x_{t+k}, y_t)
The result helps identify lagged lead-lag structure before normalization into cross-correlation.
Excel Usage
=CCOVF(x, y, adjusted, demean, fft)
x(list[list], required): First time series as a 2D range.y(list[list], required): Second time series as a 2D range.adjusted(bool, optional, default: true): Use denominator n-k instead of n in covariance estimation.demean(bool, optional, default: true): Subtract sample means from both series before covariance estimation.fft(bool, optional, default: true): Use FFT-based convolution.
Returns (list[list]): 2D table with columns lag and ccovf.
Example 1: Cross-covariance with default options
Inputs:
| x | y | adjusted | demean | fft | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 2 | 3 | 4 | 5 | 6 | 7 | true | true | true |
Excel formula:
=CCOVF({1,2,3,4,5,6}, {2,3,4,5,6,7}, TRUE, TRUE, TRUE)
Expected output:
| Result | |
|---|---|
| 0 | 2.91667 |
| 1 | 1.75 |
| 2 | 0.25 |
| 3 | -1.58333 |
| 4 | -3.75 |
| 5 | -6.25 |
Example 2: Cross-covariance without demeaning
Inputs:
| x | y | adjusted | demean | fft | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 3 | 5 | 4 | 6 | 5 | 7 | 1 | 2 | 2 | 3 | 3 | 4 | true | false | true |
Excel formula:
=CCOVF({3,5,4,6,5,7}, {1,2,2,3,3,4}, TRUE, FALSE, TRUE)
Expected output:
| Result | |
|---|---|
| 0 | 13.6667 |
| 1 | 12.2 |
| 2 | 11.75 |
| 3 | 10 |
| 4 | 9.5 |
| 5 | 7 |
Example 3: Cross-covariance without FFT
Inputs:
| x | y | adjusted | demean | fft | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2 | 4 | 3 | 5 | 4 | 6 | 5 | 1 | 3 | 2 | 4 | 3 | 5 | 4 | false | true | false |
Excel formula:
=CCOVF({2,4,3,5,4,6,5}, {1,3,2,4,3,5,4}, FALSE, TRUE, FALSE)
Expected output:
| Result | |
|---|---|
| 0 | 1.55102 |
| 1 | 0.0991254 |
| 2 | 0.565598 |
| 3 | -0.457726 |
| 4 | -0.134111 |
| 5 | -0.586006 |
| 6 | -0.262391 |
Example 4: Cross-covariance with unadjusted denominator
Inputs:
| x | y | adjusted | demean | fft | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 3 | 2 | 4 | 3 | 5 | 4 | 6 | 2 | 1 | 3 | 2 | 4 | 3 | 5 | 4 | false | true | true |
Excel formula:
=CCOVF({1,3,2,4,3,5,4,6}, {2,1,3,2,4,3,5,4}, FALSE, TRUE, TRUE)
Expected output:
| Result | |
|---|---|
| 0 | 0.75 |
| 1 | 1.3125 |
| 2 | -0.0625 |
| 3 | 0.3125 |
| 4 | -0.625 |
| 5 | -0.3125 |
| 6 | -0.6875 |
| 7 | -0.3125 |
Python Code
import numpy as np
from statsmodels.tsa.stattools import ccovf as sm_ccovf
def ccovf(x, y, adjusted=True, demean=True, fft=True):
"""
Estimate cross-covariance values between two time series across lags.
See: https://www.statsmodels.org/stable/generated/statsmodels.tsa.stattools.ccovf.html
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): First time series as a 2D range.
y (list[list]): Second time series as a 2D range.
adjusted (bool, optional): Use denominator n-k instead of n in covariance estimation. Default is True.
demean (bool, optional): Subtract sample means from both series before covariance estimation. Default is True.
fft (bool, optional): Use FFT-based convolution. Default is True.
Returns:
list[list]: 2D table with columns lag and ccovf.
"""
try:
def to1d(values):
if isinstance(values, list):
if all(isinstance(row, list) for row in values):
raw = [item for row in values for item in row]
else:
raw = values
else:
raw = [values]
out = []
for item in raw:
try:
out.append(float(item))
except (TypeError, ValueError):
continue
return out
x_vals = to1d(x)
y_vals = to1d(y)
if len(x_vals) < 2 or len(y_vals) < 2:
return "Error: x and y must each contain at least two numeric values"
if len(x_vals) != len(y_vals):
return "Error: x and y must have the same number of numeric values"
ccovf_vals = sm_ccovf(
np.asarray(x_vals, dtype=float),
np.asarray(y_vals, dtype=float),
adjusted=adjusted,
demean=demean,
fft=fft,
)
arr = np.asarray(ccovf_vals, dtype=float)
return [[lag, float(arr[lag])] for lag in range(len(arr))]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
First time series as a 2D range.
Second time series as a 2D range.
Use denominator n-k instead of n in covariance estimation.
Subtract sample means from both series before covariance estimation.
Use FFT-based convolution.