σμ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.5·~55 minAdvanced

A vector autoregression of the market

Skill positionModule 2 of 3 · Topic 5 of 9
2.5 A vector autoregression of the market
—Lab score— / 100Total XP—Streak—

Several series, each explaining the others

A vector autoregression of order p regresses the vector yₜ of k variables on its own p lags: yₜ=c+A₁yₜ₋₁+…+Aₚyₜ₋ₚ+eₜ. Each equation has the same regressors, so each can be estimated by ordinary least squares, and the matrix entry (A₁)ⱼᵢ says how much variable i last period moves variable j now. VAR(data).select_order(6) compares lags 1 to 6 with the AIC, BIC and others (BIC prefers fewer lags, because it charges more for each parameter); VAR(data).fit(p) estimates the model; res.is_stable() checks that all roots of the lag polynomial lie outside the unit circle, which is what makes shocks fade. With monthly SPY return, log volatility and the change of the 10-year yield over 258 months, AIC picks 2 lags and BIC picks 1.

Granger causality is a prediction statement, not a causal one: x Granger-causes y if the lags of x add predictive power for y beyond the lags of y itself, tested by an F test that the coefficients of x in the y equation are all zero. res.test_causality('lvol', ['ret'], kind='f') gives the statistic and the p-value. In the data, stock returns lead volatility (p=0.005) and yields (0.006); volatility (0.95) and yield changes (0.74) do not lead returns. An impulse response follows a shock through the system: it is the entry (j,i) of A₁^s after s steps (for a VAR(1)). A unit shock to the monthly return (100%) lowers log volatility by 1.82 the next month, then 0.87, 0.49, 0.27, fading as the system is stable; for a 5% fall multiply by -0.05, a rise of about 9% in volatility, the leverage effect. res.forecast(last_obs, steps) iterates the model from the last p observations and gives joint forecasts: log volatility drifts from -2.12 toward its mean.

  • Pick the lag with AIC and BIC (BIC prefers fewer), then check the system is stable.
  • Granger causality is predictive, not causal: an F test on the lags of one variable in another's equation.
  • Impulse responses show how a shock fades; scale a unit shock to a realistic size before reading it.

Lab · what's graded

  • Choosing the lag10 pts
  • Fitting the VAR10 pts
  • A Granger test15 pts
  • The Granger table10 pts
  • The impulse response15 pts
  • The joint forecast10 pts
  • The VAR study30 pts
Explorer · lab-sx-17
▾ lab-sx-17
▾ data
…
bash · in-browser
learner@quantcraft:~/lab-sx-17$
Python not loaded yetPythonLn 1, Col 1Spaces: 4UTF-8

Reset this topic?

Everything in lab-sx-17 goes back to the starter files and the terminal is cleared. Your current solution will be lost — this can't be undone.

Will be reset
  • main.py → starter code
  • Terminal history and test output
  • Unsubmitted changes
Will be kept
  • Best lab score
  • Your XP and streak
  • Lecture progress and notes

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