σμ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 3 · A market that keeps changing›Topic 3.1·~55 minAdvanced

Drift detection and change points

Skill positionModule 3 of 3 · Topic 1 of 3
3.1 Drift detection and change points
—Lab score— / 100Total XP—Streak—

When the market changes its mind

A series is stationary if its statistics, such as the mean and the spread, stay the same over time. Markets are not. A strategy may have a steady mean for years and then lose it, volatility may sit near 7%7\%7% and then jump, and a correlation may break in a crisis. These changes come in three shapes: a sudden jump (a level shift), a slow slide (drift) and a switch between regimes. The SPY return has an annual volatility of 6.8%6.8\%6.8% in 2017, 41.1%41.1\%41.1% in 2008 and 33.7%33.7\%33.7% in 2020. A single estimate from the whole history describes none of these years well, so we need to notice changes and then adapt.

xt=rt2σ02,St=max⁡(0, St−1+xt−1−k),St>hx_t=\frac{r_t^{2}}{\sigma_0^{2}},\qquad S_t=\max\left(0,\ S_{t-1}+x_t-1-k\right),\qquad S_t>hxt​=σ02​rt2​​,St​=max(0, St−1​+xt​−1−k),St​>h(1)

The CUSUM (cumulative sum) detector is the classic tool. Fix a baseline volatility σ0\sigma_0σ0​ from a calm period and measure each day by xt=rt2/σ02x_t=r_t^{2}/\sigma_0^{2}xt​=rt2​/σ02​, which averages 111 when nothing has changed. Add xt−1−kx_t-1-kxt​−1−k to a running total SSS each day, where kkk is an allowance that ignores small excesses, and never let the total go below zero. When the total passes a threshold hhh, raise the alarm. Resetting at zero is the key: a long calm stretch cannot bank credit that later hides a real change. A small kkk or hhh reacts faster but raises more false alarms.

A hand run and real SPYTake x=0.5, 3, 4, 2, 0.2x=0.5,\ 3,\ 4,\ 2,\ 0.2x=0.5, 3, 4, 2, 0.2 with k=0.5k=0.5k=0.5 and h=4h=4h=4. The total goes S=0, 1.5, 4.0, 4.5, 3.2S=0,\ 1.5,\ 4.0,\ 4.5,\ 3.2S=0, 1.5, 4.0, 4.5, 3.2. It first passes 444 on day 444. A −2%-2\%−2% day, with σ0=0.431%\sigma_0=0.431\%σ0​=0.431% per day, gives x=(2/0.431)2=21.5x=(2/0.431)^{2}=21.5x=(2/0.431)2=21.5, a huge step. On SPY, with the baseline taken from 2017 (6.85%6.85\%6.85% per year), k=0.5k=0.5k=0.5 and h=5h=5h=5, the first alarm is on 26 January 2018, days before the February 2018 sell-off, and by 16 March 2020 the total has grown to over 300030003000. The variance ratio between 2008 and 2017 is (41.1/6.75)2=37(41.1/6.75)^{2}=37(41.1/6.75)2=37 times.

Detection is only half the job. A particle filter can also raise a flag by itself: when today's return is very unlikely under the current cloud, the average likelihood is tiny and the effective sample size collapses, as on 10 October 2018. After an alarm you can widen the filter's noise so that it follows the new level faster, restart it from a flatter belief or switch to an estimator with a shorter memory, which is the next topic.

  • Three shapes of change: a jump, a drift and a switch of regime.
  • CUSUM: a running total of excess evidence that is reset at zero and raises an alarm above a threshold.
  • Speed against false alarms: a lower threshold finds changes sooner but cries wolf more often.

Lab · what's graded

  • The total on day two10 pts
  • The total on day four10 pts
  • The first alarm day10 pts
  • A standardised squared return15 pts
  • A variance ratio10 pts
  • Lowering the threshold10 pts
  • A monitoring loop10 pts
  • Match the vocabulary10 pts
  • Why reset at zero15 pts
0/ 9 answered
Tasks
1Numeric answer10 ptsNot answered

Start with S=0S=0S=0. The values are x=0.5, 3, 4, 2, 0.2x=0.5,\ 3,\ 4,\ 2,\ 0.2x=0.5, 3, 4, 2, 0.2, with k=0.5k=0.5k=0.5. Use St=max⁡(0, St−1+xt−1−k)S_t=\max(0,\ S_{t-1}+x_t-1-k)St​=max(0, St−1​+xt​−1−k). What is SSS on day two? Give one decimal.

S=S =S=accepted: ± 0.05
2Numeric answer10 ptsNot answered

Continue the same run. On day three S=4.0S=4.0S=4.0 and x4=2x_4=2x4​=2. What is SSS on day four? Give one decimal.

S=S =S=accepted: ± 0.05
3Numeric answer10 ptsNot answered

The totals are S=0, 1.5, 4.0, 4.5, 3.2S=0,\ 1.5,\ 4.0,\ 4.5,\ 3.2S=0, 1.5, 4.0, 4.5, 3.2 and the alarm is raised when S>4S>4S>4. On which day does the alarm first go off?

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

The baseline daily volatility is σ0=0.431%\sigma_0=0.431\%σ0​=0.431%. A day with return −2%-2\%−2% gives x=r2/σ02x=r^{2}/\sigma_0^{2}x=r2/σ02​. What is xxx? Give one decimal.

x=x =x=accepted: ± 0.3
5Numeric answer10 ptsNot answered

The annual volatility of SPY was 41.1%41.1\%41.1% in 2008 and 6.75%6.75\%6.75% in 2017. By what factor is the variance in 2008 larger? Give one decimal.

r=r =r=accepted: ± 0.5
6Choice10 ptsNot answered

You lower the CUSUM threshold hhh. What is the usual effect?

7Order the steps10 ptsNot answered

Put the daily steps of a CUSUM monitor 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. 1Never let the total go below zero
  2. 2Standardise today's squared return by the baseline variance
  3. 3Compare the total with the threshold and raise the alarm if it is above
  4. 4Add the excess over one plus the allowance k to the total
8Match10 ptsNot answered

Match each term with its meaning.

Pick the partner of each item on the left.

Level shift
Drift
Regime switch
CUSUM
9Explain in words15 ptsNot answered

In one or two sentences, explain why the CUSUM total is never allowed to go below zero.

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