Skip to content
LeetQuant
E07 Advanced Time Series

E07 · Advanced Time Series · Lesson 3 of 4

Vector Autoregressions

The VAR(1) and its companion form, stationarity from eigenvalues, the mean and covariance, Granger causality and its pitfalls, impulse responses with the Cholesky ordering problem, and estimating and reading a small VAR in statsmodels.

18 min

Objective

An AR model asks how a series depends on its own past. A vector autoregression asks how several series depend on each other's past: does order flow lead returns, do futures lead the cash index, do rates lead credit spreads? You should be able to check a VAR for stationarity, compute its mean and impulse responses by hand for two variables, run and interpret a Granger causality test, and say what a VAR cannot tell you.

The model

A VAR(pp) for a kk-vector yty_t:

yt=c+A1yt−1+⋯+Apyt−p+εt,εt∼(0,Σ) iid.y_t = c + A_1 y_{t-1} + \dots + A_p y_{t-p} + \varepsilon_t, \qquad \varepsilon_t \sim (0, \Sigma) \text{ iid}.

Each equation is an ordinary regression of one variable on pp lags of all kk variables, so OLS equation by equation is efficient (all equations share the same regressors). Element (A1)ij(A_1)_{ij} is the effect of yesterday's yjy_j on today's yiy_i. Contemporaneous links live only in Σ\Sigma, the covariance of the shocks.

The parameter count is the main practical constraint: k(kp+1)k(kp + 1) coefficients plus k(k+1)/2k(k+1)/2 in Σ\Sigma. Ten variables with five lags is 510 coefficients, which daily data cannot pin down. Keep VARs small, or shrink (Bayesian VARs with Minnesota priors, or factor-augmented VARs).

Stationarity, mean and covariance

Any VAR(pp) is a VAR(1) in the stacked state (yt′,yt−1′,…,yt−p+1′)′(y_t', y_{t-1}', \dots, y_{t-p+1}')', with the companion matrix from the state-space lesson. So it suffices to study yt=c+Ayt−1+εty_t = c + Ay_{t-1} + \varepsilon_t:

  • Stationary iff every eigenvalue of AA has modulus below 1. Small entries are not enough: feedback between variables can push an eigenvalue past 1.
  • Mean: μ=(I−A)−1c\mu = (I - A)^{-1}c.
  • Covariance: Γ0=AΓ0A′+Σ\Gamma_0 = A\Gamma_0A' + \Sigma (Lyapunov again), and Γh=AhΓ0\Gamma_h = A^h\Gamma_0 for the lag-hh cross-covariances Cov⁡(yt+h,yt)\operatorname{Cov}(y_{t+h}, y_t).
  • Persistence: deviations from the mean decay like ∣λmax⁡∣h|\lambda_{\max}|^h.

If an eigenvalue equals 1 the series have unit roots. Differencing every series is wrong if they are cointegrated; the right model is then the vector error-correction model Δyt=Πyt−1+…\Delta y_t = \Pi y_{t-1} + \dots, with the rank of Π\Pi equal to the number of cointegrating relations (the Johansen test).

Granger causality

xx Granger-causes yy if past xx improves forecasts of yy given past yy. In a VAR it is a test that the lag coefficients of xx in the yy equation are jointly zero, an F (or Wald) test with pp restrictions.

It is a statement about predictive content, not causation. It goes wrong in predictable ways:

  • Omitted common drivers. If zz drives both with different delays, xx appears to cause yy.
  • Stale prices and asynchronous trading. An illiquid asset's last trade price lags the liquid one mechanically; the "lead–lag" is measurement, not information flow, and is not tradable once costs are included.
  • Expectations. Prices Granger-cause the events they anticipate (the futures price "causes" the harvest).
  • Sampling frequency. A lead of minutes looks like contemporaneous correlation (in Σ\Sigma, not AA) in daily data.
  • Non-stationary levels make the test statistics non-standard; test on stationary transformations, or use the Toda–Yamamoto approach in levels.

Impulse responses

The impulse response of yi,t+hy_{i,t+h} to a unit shock in εj,t\varepsilon_{j,t} is the (i,j)(i,j) entry of AhA^h (for a VAR(1); in general the MA(∞\infty) coefficients Ψh\Psi_h). The cumulative long-run response is (I−A)−1(I - A)^{-1}.

Shocks are usually correlated, so "a shock to xx holding yy's shock fixed" is not a realistic experiment. The standard fix orthogonalises with the Cholesky factor Σ=LL′\Sigma = LL' and reports AhLA^hL. This imposes a recursive ordering: the first variable's shock may move every variable on impact, the last variable's shock moves only itself. Different orderings give different answers whenever the shocks are correlated, so the ordering is an identifying assumption you must justify (fast-moving market variables last, slow macro variables first, is the usual convention). Forecast-error variance decompositions inherit the same assumption.

Worked example

a two-variable VAR by hand

yt=c+Ayt−1+εty_t = c + Ay_{t-1} + \varepsilon_t with

A=(0.50.10.40.5),c=(11),Σ=(10.50.51).A = \begin{pmatrix} 0.5 & 0.1 \\ 0.4 & 0.5 \end{pmatrix}, \quad c = \begin{pmatrix} 1 \\ 1 \end{pmatrix}, \quad \Sigma = \begin{pmatrix} 1 & 0.5 \\ 0.5 & 1 \end{pmatrix} .

(a) Is it stationary? (b) Find the mean. (c) Trace the response of both variables to a unit shock in ε1\varepsilon_1 for h=0,…,3h = 0, \dots, 3, and the cumulative long-run response. (d) What is the impact response of y2y_2 to a one-standard-deviation orthogonalised shock in y1y_1, with y1y_1 ordered first and with y1y_1 ordered last?

Show solution

(a) The characteristic polynomial is λ2−(tr⁡A)λ+det⁡A=λ2−λ+0.21\lambda^2 - (\operatorname{tr}A)\lambda + \det A = \lambda^2 - \lambda + 0.21, so λ=(1±0.4)/2=0.7\lambda = (1 \pm 0.4)/2 = 0.7 and 0.30.3. Both inside the unit circle: stationary, with deviations decaying roughly like 0.7h0.7^h.

(b) I−A=(0.5−0.1−0.40.5)I - A = \begin{pmatrix} 0.5 & -0.1 \\ -0.4 & 0.5 \end{pmatrix} has determinant 0.210.21, so

μ=10.21(0.50.10.40.5)(11)=(2.8574.286).\mu = \frac{1}{0.21}\begin{pmatrix} 0.5 & 0.1 \\ 0.4 & 0.5 \end{pmatrix}\begin{pmatrix} 1 \\ 1 \end{pmatrix} = \begin{pmatrix} 2.857 \\ 4.286 \end{pmatrix} .

(c) The response is the first column of AhA^h:

hh0123
y1y_110.50.290.185
y2y_200.40.400.316

For example, h=2h = 2: A2=(0.290.100.400.29)A^2 = \begin{pmatrix} 0.29 & 0.10 \\ 0.40 & 0.29 \end{pmatrix}. The response of y2y_2 is hump-shaped: it builds for two periods before decaying, something a univariate AR(1) cannot produce. The cumulative response is the first column of (I−A)−1(I - A)^{-1}: (0.5,0.4)/0.21=(2.381,1.905)(0.5, 0.4)/0.21 = (2.381, 1.905). Since A12=0.1≠0A_{12} = 0.1 \ne 0 and A21=0.4≠0A_{21} = 0.4 \ne 0, each variable Granger-causes the other.

(d) The Cholesky factor with y1y_1 first is L=(100.50.866)L = \begin{pmatrix} 1 & 0 \\ 0.5 & 0.866 \end{pmatrix}, so a one-s.d. shock to y1y_1 moves y2y_2 by 0.50.5 on impact. With y1y_1 last, y2y_2's shock absorbs all the common component, the orthogonalised y1y_1 shock has s.d. 1−0.25=0.866\sqrt{1 - 0.25} = 0.866, and its impact on y2y_2 is 00 by construction. Same data, opposite stories: the ordering decides.

Estimating a small VAR

Simulate a system where xx leads yy but not the reverse, then see whether the tools recover it.

import numpy as np
import pandas as pd
from statsmodels.tsa.api import VAR

# Simulate a VAR(1) in which x leads y but y does not feed back into x
rng = np.random.default_rng(1)
A = np.array([[0.6, 0.0],    # x_t = 0.6 x_{t-1}                + e1
              [0.4, 0.3]])   # y_t = 0.4 x_{t-1} + 0.3 y_{t-1}  + e2
n = 1000
z = np.zeros((n, 2))
for t in range(1, n):
    z[t] = A @ z[t - 1] + rng.normal(size=2)
data = pd.DataFrame(z, columns=["x", "y"])

model = VAR(data)
print("lag order by AIC:", model.select_order(maxlags=6).aic)
res = model.fit(1)
print("A_hat:\n", np.round(res.coefs[0], 3))
print("eigenvalue moduli:", np.round(np.abs(np.linalg.eigvals(res.coefs[0])), 3))
for causing, caused in [("x", "y"), ("y", "x")]:
    test = res.test_causality(caused, [causing], kind="f")
    print(f"{causing} -> {caused}: F = {test.test_statistic:.1f}, p = {test.pvalue:.3g}")
irf = res.irf(5).irfs[:, 1, 0]   # response of y to a unit shock in x
print("IRF of y to x shock:", np.round(irf, 3))
print("true IRF:           ", np.round([np.linalg.matrix_power(A, h)[1, 0] for h in range(6)], 3))

Output:

lag order by AIC: 1
A_hat:
 [[0.58  0.039]
 [0.393 0.294]]
eigenvalue moduli: [0.626 0.248]
x -> y: F = 211.0, p = 1.59e-45
y -> x: F = 2.1, p = 0.148
IRF of y to x shock: [0.    0.393 0.343 0.239 0.155 0.099]
true IRF:            [0.    0.4   0.36  0.252 0.162 0.1  ]

How to read it, in the order you would say it in an interview:

  1. Lag order. AIC picks 1, matching the truth. BIC is stricter and is the safer default for forecasting; AIC is fine for testing.
  2. Coefficients. Row ii of A^\hat A is the equation for variable ii. The estimated 0.0390.039 for "lagged yy in the xx equation" is noise around the true zero (standard error about 0.0270.027 here).
  3. Stability. Eigenvalue moduli 0.6260.626 and 0.2480.248 are inside the unit circle, close to the true 0.60.6 and 0.30.3.
  4. Granger. x→yx \to y is overwhelming; y→xy \to x has p=0.15p = 0.15, so no evidence of feedback. With one lag each test has one restriction, so FF is the squared t-statistic of that single coefficient.
  5. Impulse response. irfs are the non-orthogonalised responses (AhA^h); orth_irfs apply the Cholesky ordering of the columns in the DataFrame. Here the estimated shock covariance is close to the identity, so the two nearly coincide, but on real data check which one you are reading.

Before trusting a VAR on real data: check the residuals for remaining autocorrelation (res.test_whiteness()), make sure the series are stationary or handle cointegration, and test stability of the coefficients across sub-samples. Lead–lag relations in markets are often strong in-sample and arbitraged away out of sample.

Knowledge check

A VAR(1) has A=(0.90.30.20.8)A = \begin{pmatrix} 0.9 & 0.3 \\ 0.2 & 0.8 \end{pmatrix}. Is it stationary?

Knowledge check

A VAR shows that an illiquid small-cap index Granger-causes nothing, but a liquid large-cap index strongly Granger-causes the small-cap index at a one-day lag. What is the most likely explanation?

Knowledge check

Two VAR shocks have correlation 0.6. You compute orthogonalised impulse responses with the Cholesky factor. What happens if you swap the order of the two variables?

Knowledge check

How many slope and intercept coefficients does a VAR with 10 variables and 5 lags have (excluding the error covariance)?

Key takeaways

  • A VAR(pp) regresses each variable on lags of all variables; OLS equation by equation; k(kp+1)k(kp+1) coefficients, so keep it small or shrink.
  • Stationary iff the companion matrix's eigenvalues are inside the unit circle; mean (I−A)−1c(I-A)^{-1}c; covariance from Γ0=AΓ0A′+Σ\Gamma_0 = A\Gamma_0A' + \Sigma. With unit roots and cointegration, use a VECM.
  • Granger causality is predictive content, vulnerable to omitted drivers, stale prices, expectations and sampling frequency.
  • Impulse responses are AhA^h; orthogonalised ones AhLA^hL depend on the Cholesky ordering, which is an assumption to state and defend.
  • Read a fitted VAR in order: lag choice, coefficients, stability, Granger tests, impulse responses, residual whiteness.

Practice problems

Finished reading?

Answer the 4 knowledge checks to complete this lesson (0 done).