σμ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
  • 日本語
  • 中文
Particle filtering and non-stationary time series skill›Module 1 · Hidden states that move›Topic 1.2·~50 minAdvanced

The Kalman filter recap

Skill positionModule 1 of 3 · Topic 2 of 2
1.2 The Kalman filter recap
—Lab score— / 100Total XP—Streak—

The filter for bell curves

When the state moves in a straight-line way and all noise is bell-shaped, something nice happens: the belief about the state stays a bell curve forever. A bell curve needs only two numbers, its mean mmm and its variance PPP, so a filter has to carry just those two. This is the Kalman filter, and it is the exact answer in this setting. Each day it does two steps. Predict: the mean stays, the variance grows by qqq. Update: the observation yyy pulls the mean toward itself by a fraction KKK, called the gain, and the variance shrinks.

P−=P+q,K=P−P−+r,m=m−+K (y−m−),P=(1−K) P−P^{-}=P+q,\quad K=\frac{P^{-}}{P^{-}+r},\quad m=m^{-}+K\,(y-m^{-}),\quad P=(1-K)\,P^{-}P−=P+q,K=P−+rP−​,m=m−+K(y−m−),P=(1−K)P−(1)

The update is just a weighted average: the new mean is (1−K) m−+K y(1-K)\,m^{-}+K\,y(1−K)m−+Ky. The gain KKK lies between 000 and 111. It is close to 111 when the prediction is very uncertain (large P−P^{-}P−) or the observation is precise (small rrr), so you trust the data. It is close to 000 in the opposite case, so you trust the prediction. The difference y−m−y-m^{-}y−m− is the surprise, called the innovation. Every update shrinks the variance, because 1−K<11-K<11−K<1, while every prediction grows it by qqq. Run long enough and the two balance at a steady level.

Two days of filteringTake the belief N(0,2)N(0,2)N(0,2), q=0.5q=0.5q=0.5, r=1r=1r=1 and the first observation y1=2y_1=2y1​=2. Predict: P−=2.5P^{-}=2.5P−=2.5. Gain: K=2.5/3.5=0.714K=2.5/3.5=0.714K=2.5/3.5=0.714. Update: m1=0+0.714×2=1.429m_1=0+0.714\times2=1.429m1​=0+0.714×2=1.429 and P1=(1−0.714)×2.5=0.714P_1=(1-0.714)\times2.5=0.714P1​=(1−0.714)×2.5=0.714. Next day, y2=1y_2=1y2​=1: predict P−=0.714+0.5=1.214P^{-}=0.714+0.5=1.214P−=0.714+0.5=1.214 and K=1.214/2.214=0.548K=1.214/2.214=0.548K=1.214/2.214=0.548. The surprise is 1−1.429=−0.4291-1.429=-0.4291−1.429=−0.429, so m2=1.429−0.548×0.429=1.194m_2=1.429-0.548\times0.429=1.194m2​=1.429−0.548×0.429=1.194. In the long run the prediction variance settles where P−=q+P−r/(P−+r)P^{-}=q+P^{-}r/(P^{-}+r)P−=q+P−r/(P−+r), which for these numbers is exactly 111 and gives a steady gain of 0.50.50.5.

The same filter tracks a time-varying beta. The state is the beta βt\beta_tβt​, which drifts like a random walk, and the observation is a stock's return yt=βt mt+ety_t=\beta_t\,m_t+e_tyt​=βt​mt​+et​, where mtm_tmt​ is the market return. The only change is that the gain becomes K=P−mt/(P−mt2+r)K=P^{-}m_t/(P^{-}m_t^{2}+r)K=P−mt​/(P−mt2​+r): a big market move teaches a lot about beta, a day with mt≈0m_t\approx0mt​≈0 teaches almost nothing. On Apple against SPY since 2005, the full-sample beta is 1.071.071.07, while a Kalman filter with q=10−3q=10^{-3}q=10−3 puts it at 0.770.770.77 at the end of 2008, 1.421.421.42 at the end of 2018 and 0.400.400.40 on the last day, with a standard error of about 0.250.250.25.

  • Two numbers per day: a mean and a variance are enough when everything is linear and bell-shaped.
  • The gain is a trust dial: KKK near 111 trusts the new data, near 000 trusts the prediction.
  • Limits: if the volatility itself is hidden or the noise has fat tails, the belief is no longer a bell curve and we need particles.

Lab · what's graded

  • The first gain15 pts
  • The updated mean15 pts
  • The updated variance10 pts
  • Day two15 pts
  • The steady level10 pts
  • A noisier observation10 pts
  • Match the vocabulary10 pts
  • Why an update shrinks the variance15 pts
0/ 8 answered
Tasks
1Numeric answer15 ptsNot answered

With predicted variance P−=2.5P^{-}=2.5P−=2.5 and measurement noise r=1r=1r=1, what is the gain K=P−/(P−+r)K=P^{-}/(P^{-}+r)K=P−/(P−+r)? Give three decimals.

K=K =K=accepted: ± 0.002
2Numeric answer15 ptsNot answered

The predicted mean is 000, the observation is y1=2y_1=2y1​=2 and the gain is K=0.714K=0.714K=0.714. What is the updated mean m1=m−+K(y1−m−)m_1=m^{-}+K(y_1-m^{-})m1​=m−+K(y1​−m−)? Give three decimals.

m=m =m=accepted: ± 0.003
3Numeric answer10 ptsNot answered

With P−=2.5P^{-}=2.5P−=2.5 and K=0.714K=0.714K=0.714, what is the updated variance P1=(1−K)P−P_1=(1-K)P^{-}P1​=(1−K)P−? Give three decimals.

P=P =P=accepted: ± 0.003
4Numeric answer15 ptsNot answered

On day two the predicted mean is 1.4291.4291.429 and the gain is K=0.548K=0.548K=0.548. The new observation is y2=1y_2=1y2​=1. What is the updated mean m2m_2m2​? Give three decimals.

m=m =m=accepted: ± 0.003
5Numeric answer10 ptsNot answered

In the long run the predicted variance aaa satisfies a=q+a r/(a+r)a=q+a\,r/(a+r)a=q+ar/(a+r). Check which value solves it for q=0.5q=0.5q=0.5, r=1r=1r=1: does a=1a=1a=1 work? Enter the value of q+a r/(a+r)q+a\,r/(a+r)q+ar/(a+r) when a=1a=1a=1.

v=v =v=accepted: ± 0.001
6Choice10 ptsNot answered

The measurement noise rrr becomes much larger while everything else stays the same. What happens to the gain and to the updated mean?

7Match10 ptsNot answered

Match each term with its meaning.

Pick the partner of each item on the left.

Gain K
Innovation
Predicted variance
Updated variance
8Explain in words15 ptsNot answered

In one or two sentences, explain why the variance after an update, P=(1−K)P−P=(1-K)P^{-}P=(1−K)P−, is never larger than the predicted variance.

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