σμ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.2·~50 minAdvanced

Choosing the number of regimes

Skill positionModule 3 of 3 · Topic 2 of 4
3.2 Choosing the number of regimes
—Lab score— / 100Total XP—Streak—

How many regimes are enough?

Should the market have two regimes, three, four? You cannot decide by the fit alone. A model with more states always fits the data at least as well, because it has more freedom, and with enough states it would fit noise. We need a score that rewards a good fit but charges a price for each extra parameter. The two common ones are AIC=−2ln⁡L+2p\mathrm{AIC}=-2\ln L+2pAIC=−2lnL+2p and BIC=−2ln⁡L+pln⁡n\mathrm{BIC}=-2\ln L+p\ln nBIC=−2lnL+plnn, where LLL is the likelihood of the data, ppp the number of free parameters and nnn the number of observations. Lower is better. BIC charges more per parameter when nnn is large, so it prefers simpler models.

p=K(K−1)+(K−1)+2K=K2+2K−1,AIC=−2ln⁡L+2p,BIC=−2ln⁡L+pln⁡np=K(K-1)+(K-1)+2K=K^{2}+2K-1,\qquad \mathrm{AIC}=-2\ln L+2p,\qquad \mathrm{BIC}=-2\ln L+p\ln np=K(K−1)+(K−1)+2K=K2+2K−1,AIC=−2lnL+2p,BIC=−2lnL+plnn(1)

For a Gaussian HMM with KKK states, the free parameters are the K(K−1)K(K-1)K(K−1) free transition probabilities, the K−1K-1K−1 free start probabilities and a mean and a volatility for each state, which gives p=K2+2K−1p=K^{2}+2K-1p=K2+2K−1. Fitted to the 5,4045{,}4045,404 daily returns of SPY, the log-likelihood is 16,25216{,}25216,252 for one state, 17,52117{,}52117,521 for two, 17,80317{,}80317,803 for three and 17,87717{,}87717,877 for four. The gain falls fast: 1,2691{,}2691,269, then 282282282, then only 757575. The BIC is lowest for four states, but its improvement over three is only 727272, and the extra state is hard to interpret. Interpretability, stability on new data and the size of the gain matter as much as the score.

Scores for SPYThree states have p=14p=14p=14 parameters. With ln⁡L=17,802.7\ln L=17{,}802.7lnL=17,802.7 and ln⁡n=ln⁡5404=8.595\ln n=\ln5404=8.595lnn=ln5404=8.595: BIC=−35,605.3+14×8.595=−35,485.0\mathrm{BIC}=-35{,}605.3+14\times8.595=-35{,}485.0BIC=−35,605.3+14×8.595=−35,485.0 and AIC=−35,605.3+28=−35,577.3\mathrm{AIC}=-35{,}605.3+28=-35{,}577.3AIC=−35,605.3+28=−35,577.3. Two states have p=7p=7p=7 and ln⁡L=17,520.7\ln L=17{,}520.7lnL=17,520.7, so BIC=−35,041.4+60.2=−34,981.3\mathrm{BIC}=-35{,}041.4+60.2=-34{,}981.3BIC=−35,041.4+60.2=−34,981.3, much higher (worse) than for three states. Going from three to four states adds nine parameters and only 74.574.574.5 to the log-likelihood.
  • More states always fit better, so the fit alone cannot choose the number of regimes.
  • AIC and BIC subtract a price per parameter; BIC charges ln⁡n\ln nlnn per parameter and so prefers simpler models.
  • Look at the size of the gain and at interpretability, not only at the lowest score.

Lab · what's graded

  • Parameters of three states10 pts
  • Parameters of two states10 pts
  • A BIC15 pts
  • An AIC15 pts
  • The gain from a fourth state10 pts
  • Why not just the best fit10 pts
  • Match the vocabulary15 pts
  • Why keep three regimes15 pts
0/ 8 answered
Tasks
1Numeric answer10 ptsNot answered

How many free parameters does a Gaussian HMM with K=3K=3K=3 states have, K(K−1)+(K−1)+2KK(K-1)+(K-1)+2KK(K−1)+(K−1)+2K?

p=p =p=accepted: ± 0.01
2Numeric answer10 ptsNot answered

How many free parameters does the model with K=2K=2K=2 states have?

p=p =p=accepted: ± 0.01
3Numeric answer15 ptsNot answered

For two states, ln⁡L=17520.7\ln L=17520.7lnL=17520.7, p=7p=7p=7 and n=5404n=5404n=5404, so ln⁡n=8.595\ln n=8.595lnn=8.595. What is BIC=−2ln⁡L+pln⁡n\mathrm{BIC}=-2\ln L+p\ln nBIC=−2lnL+plnn? Give one decimal.

b=b =b=accepted: ± 1
4Numeric answer15 ptsNot answered

For three states, ln⁡L=17802.7\ln L=17802.7lnL=17802.7 and p=14p=14p=14. What is AIC=−2ln⁡L+2p\mathrm{AIC}=-2\ln L+2pAIC=−2lnL+2p? Give one decimal.

a=a =a=accepted: ± 1
5Numeric answer10 ptsNot answered

The log-likelihood is 17802.717802.717802.7 for three states and 17877.217877.217877.2 for four. By how much does it rise? Give one decimal.

g=g =g=accepted: ± 0.1
6Choice10 ptsNot answered

Why should you not simply choose the number of states with the highest log-likelihood?

7Match15 ptsNot answered

Match each term with its meaning.

Pick the partner of each item on the left.

AIC
BIC
p=K2+2K−1p=K^{2}+2K-1p=K2+2K−1
Overfitting
8Explain in words15 ptsNot answered

In one or two sentences, explain why three regimes may be a sensible choice for SPY even though the BIC is slightly lower with four.

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