σμ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
  • 日本語
  • 中文
Hidden Markov Models skill›Module 3 · Regimes in markets›Topic 3.3·~50 minAdvanced

Filtering versus smoothing and the look-ahead trap

Skill positionModule 3 of 3 · Topic 3 of 4
3.3 Filtering versus smoothing and the look-ahead trap
—Lab score— / 100Total XP—Streak—

A signal you cannot trade on

Regime models are popular in trading: reduce exposure when the market is stormy. But there are two ways to get the probability of a state, and only one of them is honest. Filtered probabilities αt\alpha_tαt​ use the data up to day ttt. Smoothed probabilities γt\gamma_tγt​ use the whole sample, including days after ttt. For describing history, for example to colour a chart of past regimes, smoothing is better. For trading it is a trap: on the day you must decide, the future days are not available, so a rule built on γt\gamma_tγt​ trades on information from the future. This is the look-ahead trap.

p^t+1=αt A ≠ γt+1\hat p_{t+1}=\alpha_t\,A\ \ne\ \gamma_{t+1}p^​t+1​=αt​A = γt+1​(1)

The honest recipe is to look one step ahead from what you know. After the close of day ttt you have the filtered probabilities αt\alpha_tαt​. The predicted state probabilities for tomorrow are αt A\alpha_t\,Aαt​A: move the belief one step with the transition matrix. Then decide tomorrow's exposure from these numbers and apply it to tomorrow's return. Predicted probabilities slowly forget today and drift toward the stationary distribution. One more source of cheating is easy to miss: fitting the model's numbers on the whole sample also leaks the future, so a careful test refits on past data only and rolls forward.

What the real data showsIn our small example the filtered chance of Stormy today is 0.9030.9030.903, so tomorrow's predicted chance is 0.903×0.8+0.097×0.1=0.7320.903\times0.8+0.097\times0.1=0.7320.903×0.8+0.097×0.1=0.732, and two days out 0.6130.6130.613, drifting toward the stationary 1/31/31/3. On SPY with a three-state model, staying in the market only when the high-volatility state is unlikely gives an annual Sharpe ratio of 0.660.660.66 with filtered, lagged signals, against 0.520.520.52 for buy-and-hold. The same rule on smoothed probabilities shows 1.121.121.12. That extra 0.460.460.46 is not skill. It is the future leaking into the signal.
  • Filtered uses data up to today. Smoothed also uses later days and is for describing the past.
  • Honest signal: predict tomorrow with αtA\alpha_t Aαt​A and apply it to tomorrow's return.
  • Also leaks the future: Viterbi paths and model numbers fitted on the whole sample. Refit on past data only.

Lab · what's graded

  • Tomorrow's chance of stormy15 pts
  • The day after tomorrow15 pts
  • Where predictions drift10 pts
  • How much the future inflates10 pts
  • Which signals use the future15 pts
  • An honest regime backtest10 pts
  • Match the vocabulary10 pts
  • Why the smoothed backtest looks too good15 pts
0/ 8 answered
Tasks
1Numeric answer15 ptsNot answered

Today the filtered chance of Stormy is 0.9030.9030.903 and of Calm 0.0970.0970.097. With ASS=0.8A_{SS}=0.8ASS​=0.8 and ACS=0.1A_{CS}=0.1ACS​=0.1, what is tomorrow's predicted chance of Stormy, 0.903⋅0.8+0.097⋅0.10.903\cdot0.8+0.097\cdot0.10.903⋅0.8+0.097⋅0.1? Give three decimals.

p=p =p=accepted: ± 0.003
2Numeric answer15 ptsNot answered

Tomorrow's predicted chance of Stormy is 0.7320.7320.732. What is the predicted chance two days from today, 0.732⋅0.8+0.268⋅0.10.732\cdot0.8+0.268\cdot0.10.732⋅0.8+0.268⋅0.1? Give three decimals.

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

Far in the future the predicted chance of Stormy settles at the stationary value ACS/(ACS+ASC)A_{CS}/(A_{CS}+A_{SC})ACS​/(ACS​+ASC​). What is it for ACS=0.1A_{CS}=0.1ACS​=0.1 and ASC=0.2A_{SC}=0.2ASC​=0.2? Give three decimals.

p=p =p=accepted: ± 0.003
4Numeric answer10 ptsNot answered

On SPY the Sharpe ratio is 0.660.660.66 with filtered, lagged signals and 1.121.121.12 with smoothed ones. By how much does the look-ahead inflate it? Give two decimals.

g=g =g=accepted: ± 0.01
5Choice15 ptsNot answered

Which of these quantities use data from after the day they describe? Pick all that apply.

6Order the steps10 ptsNot answered

Put the steps of an honest regime backtest in order.

Drag to reorder, or focus an item, press Space to lift it, the arrow keys to move it and Space to drop it.

  1. 1Apply the exposure to tomorrow's return
  2. 2Fit the model on past data only
  3. 3Move forward one day and refit from time to time
  4. 4Predict tomorrow with the filtered belief times A
  5. 5Filter forward to the close of today
7Match10 ptsNot answered

Match each term with its meaning.

Pick the partner of each item on the left.

Filtered probability
Smoothed probability
Predicted probability
Look-ahead trap
8Explain in words15 ptsNot answered

In one or two sentences, explain why a trading rule built on smoothed regime probabilities looks better in a backtest than it can ever be in practice.

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