σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
statsmodels skill›Module 2 · Models for time series›Topic 2.3·~55 minAdvanced

VAR and Granger causality

Skill positionModule 2 of 3 · Topic 3 of 5
2.3 VAR and Granger causality
—Lab score— / 100Total XP—Streak—

Variables that predict each other

A vector autoregression, VAR, models several series together. Each variable is regressed on the past values of all the variables, so for two series xxx and yyy and one lag, yt=c+A yt−1+uty_t=c+A\,y_{t-1}+u_tyt​=c+Ayt−1​+ut​ with yt=(xt,yt)⊤y_t=(x_t,y_t)^\topyt​=(xt​,yt​)⊤ and a 2×22\times22×2 matrix AAA. Every equation is fitted by ordinary least squares, and in statsmodels VAR(data).fit(p) does all of them at once. The model is stable when every eigenvalue of AAA lies inside the unit circle, which means shocks fade out instead of exploding. Forecasts follow by repeated multiplication. To choose the lag order ppp you compare information criteria such as AIC and BIC, which reward fit and penalise extra coefficients.

Granger causality asks a narrow question: do past values of yyy help predict xxx once the past values of xxx itself are known? You fit the equation for xxx twice, once with the lags of yyy (unrestricted, residual sum of squares RSSu\mathrm{RSS}_uRSSu​) and once without them (restricted, RSSr\mathrm{RSS}_rRSSr​), and compare with an F-statistic. A significant result says yyy leads xxx in time. It does not prove that yyy causes xxx: a third variable, or investors who anticipate, can produce the same pattern.

yt=c+A1yt−1+⋯+Apyt−p+ut,F=(RSSr−RSSu)/qRSSu/(n−k),∣λi(A)∣<1y_t=c+A_1y_{t-1}+\cdots+A_py_{t-p}+u_t,\qquad F=\frac{(\mathrm{RSS}_r-\mathrm{RSS}_u)/q}{\mathrm{RSS}_u/(n-k)},\qquad |\lambda_i(A)|<1yt​=c+A1​yt−1​+⋯+Ap​yt−p​+ut​,F=RSSu​/(n−k)(RSSr​−RSSu​)/q​,∣λi​(A)∣<1(1)
A two-variable VAR by handLet A=(0.50.20.10.6)A=\begin{pmatrix}0.5&0.2\\0.1&0.6\end{pmatrix}A=(0.50.1​0.20.6​) and start at (x,y)=(1,2)(x,y)=(1,2)(x,y)=(1,2). One step ahead is (0.5⋅1+0.2⋅2,  0.1⋅1+0.6⋅2)=(0.9,1.3)(0.5\cdot1+0.2\cdot2,\;0.1\cdot1+0.6\cdot2)=(0.9,1.3)(0.5⋅1+0.2⋅2,0.1⋅1+0.6⋅2)=(0.9,1.3) and two steps ahead is (0.5⋅0.9+0.2⋅1.3,  0.1⋅0.9+0.6⋅1.3)=(0.71,0.87)(0.5\cdot0.9+0.2\cdot1.3,\;0.1\cdot0.9+0.6\cdot1.3)=(0.71,0.87)(0.5⋅0.9+0.2⋅1.3,0.1⋅0.9+0.6⋅1.3)=(0.71,0.87). The trace is 1.11.11.1 and the determinant 0.5⋅0.6−0.2⋅0.1=0.280.5\cdot0.6-0.2\cdot0.1=0.280.5⋅0.6−0.2⋅0.1=0.28, so the eigenvalues solve λ2−1.1λ+0.28=0\lambda^2-1.1\lambda+0.28=0λ2−1.1λ+0.28=0 and equal 0.70.70.7 and 0.40.40.4: both are inside the unit circle, so the system is stable. For the F-test, if dropping the lags of yyy raises the residual sum of squares from RSSu=10\mathrm{RSS}_u=10RSSu​=10 to RSSr=12\mathrm{RSS}_r=12RSSr​=12, with q=2q=2q=2 restrictions and n−k=40n-k=40n−k=40, then F=(12−10)/210/40=4.0F=\frac{(12-10)/2}{10/40}=4.0F=10/40(12−10)/2​=4.0, above the 5% critical value 3.233.233.23.

On real monthly data, 258258258 months from March 2005, take the SPY return in percent and the 10-year minus 2-year Treasury spread. AIC picks 333 lags and BIC picks 111, and a VAR(2) is stable, with the closest root at 1.021.021.02 because the spread is very persistent (its own lags add to 0.980.980.98). The Granger test of whether the spread helps predict returns gives F=0.22F=0.22F=0.22 (p=0.81p=0.81p=0.81), and whether returns help predict the spread gives F=1.88F=1.88F=1.88 (p=0.15p=0.15p=0.15). Neither direction is significant: knowing the yield-curve slope adds nothing to a monthly forecast of SPY.

Lab · what's graded

  • One step ahead10 pts
  • Two steps ahead15 pts
  • The largest eigenvalue15 pts
  • A Granger F-statistic15 pts
  • Counting coefficients15 pts
  • Reading a Granger test10 pts
  • Prediction is not causation20 pts
0/ 7 answered
Tasks
1Numeric answer10 ptsNot answered

With A=(0.50.20.10.6)A=\begin{pmatrix}0.5&0.2\\0.1&0.6\end{pmatrix}A=(0.50.1​0.20.6​) and current values (x,y)=(1,2)(x,y)=(1,2)(x,y)=(1,2), what is the one-step forecast of xxx, 0.5x+0.2y0.5x+0.2y0.5x+0.2y?

h1=h1 =h1=accepted: ± 0.01
2Numeric answer15 ptsNot answered

The one-step forecast is (0.9,1.3)(0.9,1.3)(0.9,1.3). What is the two-step forecast of yyy, 0.1⋅0.9+0.6⋅1.30.1\cdot0.9+0.6\cdot1.30.1⋅0.9+0.6⋅1.3? Give two decimals.

h2=h2 =h2=accepted: ± 0.01
3Numeric answer15 ptsNot answered

The eigenvalues solve λ2−1.1λ+0.28=0\lambda^2-1.1\lambda+0.28=0λ2−1.1λ+0.28=0, with trace 1.11.11.1 and determinant 0.280.280.28. What is the larger root? Use 1.12−4⋅0.28=0.3\sqrt{1.1^2-4\cdot0.28}=0.31.12−4⋅0.28​=0.3 and give one decimal.

l=l =l=accepted: ± 0.01
4Numeric answer15 ptsNot answered

Dropping the lags of yyy raises the residual sum of squares from RSSu=10\mathrm{RSS}_u=10RSSu​=10 to RSSr=12\mathrm{RSS}_r=12RSSr​=12. With q=2q=2q=2 restrictions and n−k=40n-k=40n−k=40, what is F=(RSSr−RSSu)/qRSSu/(n−k)F=\frac{(\mathrm{RSS}_r-\mathrm{RSS}_u)/q}{\mathrm{RSS}_u/(n-k)}F=RSSu​/(n−k)(RSSr​−RSSu​)/q​?

F=F =F=accepted: ± 0.05
5Numeric answer15 ptsNot answered

A VAR(2) has 333 variables. Each of its 333 equations has a constant plus 222 lags of each of the 333 variables. How many coefficients does the whole model have?

n=n =n=accepted: ± 0.1
6Choice10 ptsNot answered

The test of whether the yield spread Granger-causes monthly SPY returns gives F = 0.22 with p = 0.81. What does that say?

7Explain in words20 ptsNot answered

Suppose yyy Granger-causes xxx with a very small p-value. In one or two sentences, explain why this still does not prove that yyy moves xxx.

Math modeKeyboard or LaTeX inputTask 1 of 7 · Ctrl ⏎ to check

Log in to run your code.

Every lecture is free to read. Create an account or log in to run code, run tests and submit this lab.

  • In-browser IDE with a bash terminal — nothing to install
  • Instant grading, XP and your place on the skill
Create an accountLog in
OR
Continue with GitHub