σμ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
  • 日本語
  • 中文
Time Series skill›Module 5 · Evaluation and practice›Topic 5.3·~1 hr 40 minAdvanced

Capstone: a volatility forecasting contest on real data

Skill positionModule 5 of 5 · Topic 3 of 3
5.3 Capstone: a volatility forecasting contest on real data
—Lab score— / 100Total XP—Streak—

From four models to one fair contest

Every tool of this skill answers one question: how large will tomorrow's move be? A constant variance, an exponentially weighted average, a GARCH(1,1) and a HAR regression on the daily high-low range give four different answers, and the only honest way to choose between them is a contest with fair rules. Each forecast for day t may use only data before day t. GARCH is fitted once on the first 1,000 days and never refitted. All four are scored on the days after that, against the squared return, with a loss that punishes under-predicting the variance more than over-predicting it. Only NumPy is needed.

hₜ=λhₜ₋₁+(1-λ)rₜ₋₁², hₜ=ω+αrₜ₋₁²+βhₜ₋₁, ω=(1-α-β)σ²

The EWMA and the GARCH both update a variance state with yesterday's squared return. GARCH has more room: its parameters are chosen by maximising a Gaussian likelihood, here over a small grid with the long-run variance σ² fixed to the sample value (variance targeting). The HAR model reads the range instead. Its feature for day t is built from the Parkinson variance of the days before: yesterday's value, the mean of the last 5 days and the mean of the last 22. Its target is the squared return, which is noisy but has the right level, and it is refitted every 21 days on the previous 750 days. The score is the mean QLIKE, y/h-ln(y/h)-1 with y the proxy and h the forecast, and the Diebold-Mariano statistic tells whether a difference between two forecasters is larger than luck.

QLIKE=y/h-ln(y/h)-1, DM=(mean(d))/(std(d)/√n), d=L₁-L₂
What the real data saysOn SPY, scored on the 4,404 days after the first 1,000, the mean QLIKE against the squared return is about 2.03 for the constant forecast, 1.63 for the EWMA, 1.59 for the GARCH (grid choice α=0.11, β=0.88, so a persistence of 0.99) and 1.56 for the HAR model on the range. Every step down is a better forecast. The Diebold-Mariano statistic is about 3.5 for EWMA against GARCH and 3.6 for EWMA against HAR, both far beyond 1.96. GARCH against HAR gives about 1.9, just short of significance at 5%. With a proxy as noisy as one squared return, the gaps are modest even when the ordering is clear.
  • Fair rules: a forecast for day t uses only data before day t, the GARCH is fitted before the scoring period and filtered forward with fixed parameters.
  • QLIKE is the loss, the squared return is the proxy, and Diebold-Mariano tells whether two forecasters really differ.
  • Ladder: constant, EWMA, GARCH, HAR on the range; each step lowers the loss on SPY, but the last gap is within noise.
Four simplifications to rememberThe proxy is one squared return, so all losses are high and differences are small; a realised variance would sharpen them. The GARCH is fitted once on a coarse grid and never updated, whereas a live system would refit it. The likelihood is Gaussian although returns have fat tails. And the score is for one asset in one period that includes a crisis: a winner here is not a promise for the next decade.

Lab · what's graded

  • A range-based variance10 pts
  • An EWMA forecaster15 pts
  • A GARCH filter15 pts
  • Fitting a GARCH on a grid15 pts
  • A HAR forecaster20 pts
  • The QLIKE loss10 pts
  • The Diebold-Mariano statistic5 pts
  • The contest10 pts
Explorer · lab-tz-12
▾ lab-tz-12
▾ data
…
bash · in-browser
learner@quantcraft:~/lab-tz-12$
Python not loaded yetPythonLn 1, Col 1Spaces: 4UTF-8

Reset this topic?

Everything in lab-tz-12 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