CCF
Computes the sample cross‑correlation function of two stationary time series.
Required Arguments
X — Vector of length NOBS containing the first time series. (Input)
NOBS must be greater than or equal to two.
Y — Vector of length NOBS containing the second time series. (Input)
MAXLAG — Maximum lag of cross‑covariances and cross‑correlations to be computed. (Input)
MAXLAG must be greater than or equal to one and less than NOBS.
CC — Vector of length 2 * MAXLAG + 1 containing the cross‑correlations between the time series X and Y. (Output)
The cross‑correlation between X and Y at lag k corresponds to CC(k) where k = ‑MAXLAG, …, 1, 0, 1, …, MAXLAG.
Optional Arguments
XMEAN — Estimate of the mean of time series X. (Input, if IMEAN = 0; output, if
IMEAN = 1)
Default: XMEAN = 0.0.
YMEAN — Estimate of the mean of time series Y. (Input, if IMEAN = 0; output, if
IMEAN = 1)
Default: YMEAN = 0.0.
XVAR — Variance of the time series X. (Output)
YVAR — Variance of the time series Y. (Output)
CCV — Vector of length 2 * MAXLAG + 1 containing the cross‑covariances between the time series X and Y. (Output)
The cross‑covariance between X and Y at lag k corresponds to CCV(k) where k = ‑MAXLAG, …, 1, 0, 1, …, MAXLAG.
NOBS — Number of observations in each time series. (Input)
Default: NOBS = size (X,1).
IPRINT — Printing option. (Input)
Default: IPRINT = 0.
IPRINT
Action
0
No printing is performed.
1
Prints the means and variances.
2
Prints the means, variances, and cross‑covariances.
3
Prints the means, variances, cross‑covariances, cross‑correlations, and standard errors of cross‑correlations.
ISEOPT — Option for computing standard errors of cross correlations. (Input)
Default: ISEOPT = 0.
ISOPT
Action
0
No standard errors of cross‑correlations are computed.
1
Compute standard errors of cross‑correlations using Bartlett’s formula.
2
Compute standard errors of cross‑correlations using Bartlett’s formula with the assumption of no cross‑correlation.
IMEAN — Option for computing the mean. (Input)
Default: IMEAN = 1.
IMEAN
Action
0
XMEAN and YMEAN are user specified.
1
XMEAN and YMEAN are set to the arithmetic means of X and Y.
SECC — Vector of length 2 * MAXLAG + 1 containing the standard errors of the crosscorrelations between the time series X and Y. (Output)
The standard error of CC(k) is SECC(k) where k = ‑MAXLAG, …, 1, 0, 1, …, MAXLAG.
FORTRAN 90 Interface
Generic: CALL CCF (X, Y, MAXLAG, CC[])
Specific: The specific interface names are S_CCF and D_CCF.
FORTRAN 77 Interface
Single: CALL CCF (NOBS, X, Y, MAXLAG, IPRINT, ISEOPT, IMEAN, XMEAN, YMEAN, XVAR, YVAR, CCV, CC, SECC)
Double: The double precision name is DCCF.
Description
Routine CCF estimates the cross‑correlation function of two jointly stationary time series given a sample of n = NOBS observations {Xt} and {Yt} for t = 1, 2, …, n.
Let
be the estimate of the mean μX of the time series {Xt} where
The autocovariance function of {Xt}, σX(k), is estimated by
 
where K = MAXLAG. Note that
is equivalent to the sample variance XVAR. The autocorrelation function ρX(k) is estimated by
 
Note that
by definition. Let
be similarly defined.
The cross‑covariance function σXY(k) is estimated by
The cross‑correlation function ρXY(k) is estimated by
The standard errors of the sample cross‑correlations may be optionally computed according to argument ISEOPT. One method is based on a general asymptotic expression for the variance of the sample cross‑correlation coefficient of two jointly stationary time series with independent, identically distributed normal errors given by Bartlett (1978, page 352). The theoretical formula is
For computational purposes, the autocorrelations ρX(k) and ρY(k) and the cross‑correlations ρXY(k) are replaced by their corresponding estimates for k  K, and the limits of summation are equal to zero for all k such that k > K.
A second method evaluates Bartlett’s formula under the additional assumption that the two series have no cross‑correlation. The theoretical formula is
For additional special cases of Bartlett’s formula, see Box and Jenkins (1976, page 377).
An important property of the cross‑covariance coefficient is σXY(k) = σYX(k) for k  0. This result is used in the computation of the standard error of the sample cross‑correlation for lag k < 0. In general, the cross‑covariance function is not symmetric about zero so both positive and negative lags are of interest.
Comments
1. Workspace may be explicitly provided, if desired, by use of C2F/DC2F. The reference is:
CALL C2F (NOBS, X, Y, MAXLAG, IPRINT, ISEOPT, IMEAN, XMEAN, YMEAN, XVAR, YVAR, CCV, CC, SECC, ACX, ACY)
The additional arguments are as follows:
ACX — Work vector of length equal to MAXLAG + 1.
ACY — Work vector of length equal to MAXLAG + 1.
2. If ISEOPT = 0, then no workspace is needed and SECC, ACX, and ACY can be dimensioned with length 1.
3. Autocovariances, autocorrelations, and standard errors of autocorrelations may be obtained by setting the first and second time series equal.
Example
Consider the Gas Furnace Data (Box and Jenkins 1976, pages 532–533) where X is the input gas rate in cubic feet/minute and Y is the percent CO2 in the outlet gas. Routine CCF is used to computed the cross‑covariances and cross‑correlations between time series X and Y with lags from ‑MAXLAG = 10 through lag MAXLAG = 10. In addition, the estimated standard errors of the estimated cross‑correlations are computed. In the first invocation with ISEOPT = 1, the standard errors are based on the assumption that autocorrelations and cross‑correlations for lags greater than MAXLAG or less than ‑MAXLAG are zero. In the second invocation with ISEOPT = 2, the standard errors are based on the additional assumption that all cross‑correlations for X and Y are zero.
 
USE GDATA_INT
USE CCF_INT
 
IMPLICIT NONE
 
INTEGER IPRINT, MAXLAG, NOBS
PARAMETER (IPRINT=3, MAXLAG=10, NOBS=296)
!
INTEGER IMEAN, ISEOPT, NCOL, NROW
REAL CC(-MAXLAG:MAXLAG), CCV(-MAXLAG:MAXLAG), &
RDATA(296,2), SECC(-MAXLAG:MAXLAG), X(NOBS), XMEAN, &
XVAR, Y(NOBS), YMEAN, YVAR
!
EQUIVALENCE (X(1), RDATA(1,1)), (Y(1), RDATA(1,2))
!
CALL GDATA (7, RDATA, NROW, NCOL)
! USE Default Option to estimate means.
 
! Bartlett's formula (general case)
ISEOPT = 1
! Compute cross correlation function
CALL CCF (X, Y, MAXLAG, CC, IPRINT=IPRINT, ISEOPT=ISEOPT)
! Bartlett's formula (independent case)
ISEOPT = 2
! Compute cross correlation function
CALL CCF (X, Y, MAXLAG, CC, IPRINT=IPRINT, ISEOPT=ISEOPT)
!
END
Output
Output from CCF/C2F
 
Mean of series X = -0.056834
Variance of series X = 1.1469
 
Mean of series Y = 53.509
Variance of series Y = 10.219
 
Lag CCV CC SECC
 
-10 -0.40450 -0.11815 0.158148
-9 -0.50849 -0.14853 0.155750
-8 -0.61437 -0.17946 0.152735
-7 -0.70548 -0.20607 0.149087
-6 -0.77617 -0.22672 0.145055
-5 -0.83147 -0.24287 0.141300
-4 -0.89132 -0.26035 0.138421
-3 -0.98060 -0.28643 0.136074
-2 -1.12477 -0.32854 0.132159
-1 -1.34704 -0.39347 0.123531
0 -1.65853 -0.48445 0.107879
1 -2.04865 -0.59841 0.087341
2 -2.48217 -0.72503 0.064141
3 -2.88541 -0.84282 0.046946
4 -3.16536 -0.92459 0.044097
5 -3.25344 -0.95032 0.048234
6 -3.13113 -0.91459 0.049155
7 -2.83919 -0.82932 0.047562
8 -2.45302 -0.71652 0.053478
9 -2.05269 -0.59958 0.071566
10 -1.69466 -0.49500 0.093933
 
Output from CCF/C2F
 
Mean of series X = -0.056834
Variance of series X = 1.1469
 
Mean of series Y = 53.509
Variance of series Y = 10.219
 
Lag CCV CC SECC
 
-10 -0.40450 -0.11815 0.16275
-9 -0.50849 -0.14853 0.16247
-8 -0.61437 -0.17946 0.16219
-7 -0.70548 -0.20607 0.16191
-6 -0.77617 -0.22672 0.16163
-5 -0.83147 -0.24287 0.16135
-4 -0.89132 -0.26035 0.16107
-3 -0.98060 -0.28643 0.16080
-2 -1.12477 -0.32854 0.16052
-1 -1.34704 -0.39347 0.16025
0 -1.65853 -0.48445 0.15998
1 -2.04865 -0.59841 0.16025
2 -2.48217 -0.72503 0.16052
3 -2.88541 -0.84282 0.16080
4 -3.16536 -0.92459 0.16107
5 -3.25344 -0.95032 0.16135
6 -3.13113 -0.91459 0.16163
7 -2.83919 -0.82932 0.16191
8 -2.45302 -0.71652 0.16219
9 -2.05269 -0.59958 0.16247
10 -1.69466 -0.49500 0.16275
 
 
Published date: 03/19/2020
Last modified date: 03/19/2020