Main Content


Create matrix of lagged time series


XLAG = lagmatrix(X,Lags)


XLAG = lagmatrix(X,Lags) creates a lagged (shifted) version of a time series matrix. The lagmatrix function is useful for creating a regression matrix of explanatory variables for fitting the conditional mean of a return series.

Input Arguments


Time series of explanatory data. X can be a column vector or a matrix. As a column vector, X represents a univariate time series whose first element contains the oldest observation and whose last element contains the most recent observation. As a matrix, X represents a multivariate time series whose rows correspond to time indices. The first row contains the oldest observations and the last row contains the most recent observations. lagmatrix assumes that observations across any given row occur at the same time. Each column is an individual time series.


Vector of integer lags. lagmatrix applies the first lag to every series in X, then applies the second lag to every series in X, and so forth. To include a time series as is, include a 0 lag. Positive lags correspond to delays, and shift a series back in time. Negative lags correspond to leads, and shift a series forward in time.

Output Arguments


Lagged transform of the time series X. To create XLAG, lagmatrix shifts each time series in X by the first lag, then shifts each time series in X by the second lag, and so forth. Since XLAG represents an explanatory regression matrix, each column is an individual time series. XLAG has the same number of rows as there are observations in X. Its column dimension is equal to the product of the number of columns in X and the length of Lags. lagmatrix uses a NaN (Not-a-Number) to indicate an undefined observation.


collapse all

Create a bivariate time series matrix X with five observations each:

X = [1 -1; 2 -2 ;3 -3 ;4 -4 ;5 -5]  % Create a simple
X = 5×2

     1    -1
     2    -2
     3    -3
     4    -4
     5    -5

                                    % bivariate series.

Create a lagged matrix XLAG, composed of X and the first two lags of X:

XLAG = lagmatrix(X,[0 1 2]) % Create the lagged matrix.
XLAG = 5×6

     1    -1   NaN   NaN   NaN   NaN
     2    -2     1    -1   NaN   NaN
     3    -3     2    -2     1    -1
     4    -4     3    -3     2    -2
     5    -5     4    -4     3    -3

The result, XLAG, is a 5-by-6 matrix.

See Also

| |

Introduced before R2006a