σμ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 4 · Several series and hidden states›Topic 4.2·~1 hr 10 minAdvanced

State-space models and the Kalman filter

Skill positionModule 4 of 5 · Topic 2 of 2
4.2 State-space models and the Kalman filter
—Lab score— / 100Total XP—Streak—

Tracking a hidden state

Many quantities that matter cannot be seen directly: the fair value of a stock behind noisy quotes, the hedge ratio between two assets that drifts through time, the current level of volatility. A state-space model describes them with two equations. The state evolves by itself, xt=Fxt−1+wtx_t=Fx_{t-1}+w_txt​=Fxt−1​+wt​ with noise variance QQQ. What you observe is a noisy view of it, yt=Hxt+vty_t=Hx_t+v_tyt​=Hxt​+vt​ with noise variance RRR. The Kalman filter combines the two in a loop that gives the best linear estimate of the state from the data seen so far, together with its uncertainty PPP. It is the exact solution when the noises are Gaussian and the model is linear.

x^−=x^,P−=P+Q;K=P−P−+R;x^=x^−+K (y−x^−);P=(1−K) P−\hat x^{-}=\hat x,\quad P^{-}=P+Q;\qquad K=\frac{P^{-}}{P^{-}+R};\qquad \hat x=\hat x^{-}+K\,(y-\hat x^{-});\qquad P=(1-K)\,P^{-}x^−=x^,P−=P+Q;K=P−+RP−​;x^=x^−+K(y−x^−);P=(1−K)P−(1)

The formulas above are the scalar local-level model, where the hidden level is a random walk (F=H=1F=H=1F=H=1). Each step has two parts. Predict: the best guess for the new state is the old estimate, and the uncertainty grows by QQQ to P−=P+QP^{-}=P+QP−=P+Q. Update: the gain K=P−/(P−+R)K=P^{-}/(P^{-}+R)K=P−/(P−+R) decides how far to move toward the new observation. A large RRR (a noisy measurement) gives a small KKK, so the filter trusts its own prediction; a small RRR gives KKK near 1, so it follows the data. After the update the uncertainty falls to (1−K)P−(1-K)P^{-}(1−K)P−. The prediction error y−x^−y-\hat x^{-}y−x^−, called the innovation, should be white noise if the model is right, and QQQ and RRR are usually estimated by maximising the likelihood built from the innovations.

One filter stepStart with x^=100\hat x=100x^=100 and P=4P=4P=4, with Q=1Q=1Q=1 and R=5R=5R=5. Predict: P−=4+1=5P^{-}=4+1=5P−=4+1=5. The observation is y=104y=104y=104. The gain is K=5/(5+5)=0.5K=5/(5+5)=0.5K=5/(5+5)=0.5, so the update is x^=100+0.5⋅(104−100)=102\hat x=100+0.5\cdot(104-100)=102x^=100+0.5⋅(104−100)=102 and the uncertainty falls to P=(1−0.5)⋅5=2.5P=(1-0.5)\cdot5=2.5P=(1−0.5)⋅5=2.5. The new estimate sits halfway between prediction and observation because they are equally uncertain. If the measurement were noisier, R=20R=20R=20, the gain would drop to 5/25=0.25/25=0.25/25=0.2 and the estimate would move only to 100.8100.8100.8.
  • State equation xt=Fxt−1+wtx_t=Fx_{t-1}+w_txt​=Fxt−1​+wt​ and observation equation yt=Hxt+vty_t=Hx_t+v_tyt​=Hxt​+vt​ with noise variances QQQ and RRR.
  • Kalman gain K=P−/(P−+R)K=P^{-}/(P^{-}+R)K=P−/(P−+R): near 0 means trust the model, near 1 means trust the data.
  • Uses: a time-varying hedge ratio for pairs, a fair value behind noisy prices, volatility states; innovations should be white noise.

Lab · what's graded

  • The predict step10 pts
  • The Kalman gain15 pts
  • The updated estimate15 pts
  • The updated uncertainty15 pts
  • A noisier measurement10 pts
  • A very noisy measurement10 pts
  • Match the vocabulary15 pts
  • A drifting hedge ratio10 pts
0/ 8 answered
Tasks
1Numeric answer10 ptsNot answered

The filter has uncertainty P=4P=4P=4 and the state noise is Q=1Q=1Q=1. What is the predicted uncertainty P−=P+QP^{-}=P+QP−=P+Q?

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

With P−=5P^{-}=5P−=5 and measurement noise R=5R=5R=5, what is the gain K=P−/(P−+R)K=P^{-}/(P^{-}+R)K=P−/(P−+R)?

k=k =k=accepted: ± 0.005
3Numeric answer15 ptsNot answered

The prediction is x^−=100\hat x^{-}=100x^−=100, the gain is K=0.5K=0.5K=0.5 and the observation is y=104y=104y=104. What is the updated estimate x^−+K(y−x^−)\hat x^{-}+K(y-\hat x^{-})x^−+K(y−x^−)?

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

With K=0.5K=0.5K=0.5 and P−=5P^{-}=5P−=5, what is the updated uncertainty P=(1−K)P−P=(1-K)P^{-}P=(1−K)P−?

pn=pn =pn=accepted: ± 0.01
5Numeric answer10 ptsNot answered

The measurement noise rises to R=20R=20R=20 while P−=5P^{-}=5P−=5 stays the same. What is the new gain?

k2=k2 =k2=accepted: ± 0.005
6Choice10 ptsNot answered

What happens to the Kalman gain as the measurement noise RRR grows very large?

7Match15 ptsNot answered

Match each term with its meaning.

Pick the partner of each item on the left.

State equation
Observation equation
Innovation
Kalman gain
8Explain in words10 ptsNot answered

In one or two sentences, explain why a Kalman filter can follow a drifting hedge ratio better than a regression on a fixed rolling window.

Math modeKeyboard or LaTeX inputTask 1 of 8 · 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