Products & Services Solutions Academia Support User Community Company

Learn more about Econometrics Toolbox   

crosscorr - Cross-correlation

Syntax

crosscorr(Series1,Series2,nLags,nSTDs)
[XCF,Lags,Bounds] = crosscorr(Series1,Series2,nLags,nSTDs)

Description

Input Arguments

Series1

Column vector of observations of the first univariate time series for which crosscorr computes or plots the sample cross-correlation function (XCF). The last row of Series1 contains the most recent observation.

Series2

Column vector of observations of the second univariate time series for which crosscorr computes or plots the sample XCF. The last row of Series2 contains the most recent observation.

nLags

Positive scalar integer indicating the number of lags of the XCF to compute. If nLags = [] or is unspecified, crosscorr computes the XCF at lags , where T = min([20,min([length(Series1),
length(Series2)])-1]).

nSTDs

Positive scalar indicating the number of standard deviations of the sample XCF estimation error to compute, if Series1 and Series2 are uncorrelated. If nSTDs = [] or is unspecified, the default is 2 (that is, approximate 95 percent confidence interval).

Output Arguments

XCF

Sample cross-correlation function between Series1 and Series2. XCF is a vector of length 2(nLags)+1, which corresponds to lags . The center element of XCF contains the 0th lag cross correlation.

Lags

Vector of lags corresponding to XCF(nLags, ..., +nLags).

Bounds

Two-element vector indicating the approximate upper and lower confidence bounds, assuming that Series1 and Series2 are completely uncorrelated.

Examples

Example 1

  1. Create a time series column vector of 100 Gaussian deviates:

    strm = RandStream('mt19937ar'); % reproducible
    RandStream.setDefaultStream(strm);
    x = randn(100, 1);       % 100 Gaussian deviates, N(0, 1)
  2. Create a delayed version of the vector, lagged by four samples:

    y = lagmatrix(x, 4);    % Delay it by 4 samples
  3. Compute the XCF, and then plot it to see the XCF peak at the fourth lag:

    y(isnan(y)) = 0;
    [XCF, Lags, Bounds] = crosscorr(x, y);
    [Lags, XCF]
    ans =
      -20.0000    0.1553
      -19.0000   -0.0342
      -18.0000    0.0850
      -17.0000   -0.0260
      -16.0000   -0.1304
      -15.0000    0.0498
      -14.0000   -0.0234
      -13.0000   -0.1033
      -12.0000    0.0227
      -11.0000   -0.0422
      -10.0000    0.0294
       -9.0000   -0.0099
       -8.0000   -0.0296
       -7.0000   -0.0094
       -6.0000    0.1510
       -5.0000   -0.0911
       -4.0000    0.2235
       -3.0000    0.0065
       -2.0000   -0.0452
       -1.0000    0.0792
             0   -0.1901
        1.0000    0.0321
        2.0000    0.0240
        3.0000   -0.0073
        4.0000    0.9675
        5.0000   -0.0069
        6.0000    0.0248
        7.0000    0.0232
        8.0000   -0.1529
        9.0000    0.0870
       10.0000   -0.0131
       11.0000   -0.0095
       12.0000    0.1941
       13.0000   -0.1149
       14.0000    0.1319
       15.0000    0.0063
       16.0000   -0.0184
       17.0000   -0.0068
       18.0000    0.0562
       19.0000   -0.0466
       20.0000    0.0473
    
    Bounds
    Bounds =
        0.2000
       -0.2000
    crosscorr(x, y)        % Use the same example, but plot the XCF 
                           % sequence. Note the peak at the 4th lag.
    

Example 2

See Example: Using the Default Model.

See Also

autocorr, parcorr

filter (MATLAB function)

  


Free Interactive Computational Finance CD

View demos and recorded presentations led by industry experts.

Now On Demand
Network with industry peers and learn the latest applications of the leading software product for computational finance.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS