σμ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 2 · Particle filters›Topic 2.2·~1 hr 5 minAdvanced

The bootstrap particle filter

Skill positionModule 2 of 3 · Topic 2 of 5
2.2 The bootstrap particle filter
—Lab score— / 100Total XP—Streak—

A cloud that follows the state

A particle filter keeps the belief about the hidden state as a cloud of NNN particles. Each particle is one possible value of the state, and it carries a weight that says how plausible it is. No bell curve is assumed, so the cloud can take any shape. Each day goes through the same cycle. Propagate: move every particle forward with the model's own random motion. Weight: give each particle a weight equal to the likelihood of today's observation given that particle. Estimate: the filtered mean is the weighted average of the particles. Resample: draw a fresh cloud in which good particles are copied and poor ones disappear.

xt(i)=xt−1(i)+q z(i),w(i)=p(yt∣xt(i)),m^t=∑iw~(i)xt(i),p^(yt)=1N∑iw(i)x_t^{(i)}=x_{t-1}^{(i)}+\sqrt q\,z^{(i)},\quad w^{(i)}=p(y_t\mid x_t^{(i)}),\quad \hat m_t=\sum_i\tilde w^{(i)}x_t^{(i)},\quad \hat p(y_t)=\frac1N\sum_i w^{(i)}xt(i)​=xt−1(i)​+q​z(i),w(i)=p(yt​∣xt(i)​),m^t​=i∑​w~(i)xt(i)​,p^​(yt​)=N1​i∑​w(i)(1)

This is called the bootstrap filter because the proposal is the simplest one: the model's own transition. That makes the weight of a particle exactly the likelihood. The recipe works for any model that you can simulate forward and whose observation likelihood you can evaluate, so it handles non-linear states, fat tails and hidden volatility, where the Kalman filter has no exact answer. The price is randomness. Two runs with different random numbers give slightly different answers, and the error shrinks like 1/N1/\sqrt N1/N​. In practice you fix the random seed so that a run can be reproduced.

One cycle with four particlesAfter propagation the four particles sit at −1,0,1,2-1,0,1,2−1,0,1,2, and we observe y=1y=1y=1 with r=1r=1r=1. The likelihoods are 0.054, 0.242, 0.399, 0.2420.054,\ 0.242,\ 0.399,\ 0.2420.054, 0.242, 0.399, 0.242 (the normal density with an extra 1/2π1/\sqrt{2\pi}1/2π​), and the weights are 0.058, 0.258, 0.426, 0.2580.058,\ 0.258,\ 0.426,\ 0.2580.058, 0.258, 0.426, 0.258. The filtered mean is 0.8850.8850.885. The average likelihood, 0.2340.2340.234, estimates how probable the observation was, and the sum of the logs of these averages over all days is the log-likelihood of the model. To resample, draw uniform numbers 0.05, 0.5, 0.6, 0.90.05,\ 0.5,\ 0.6,\ 0.90.05, 0.5, 0.6, 0.9 and look them up in the cumulative weights 0.058, 0.316, 0.742, 10.058,\ 0.316,\ 0.742,\ 10.058, 0.316, 0.742, 1. They pick particles 1,3,3,41,3,3,41,3,3,4, so the new cloud is −1,1,1,2-1,1,1,2−1,1,1,2 with equal weights 0.250.250.25 and mean 0.750.750.75.
  • Four steps a day: propagate, weight, estimate, resample.
  • Weight = likelihood: only the weighting step looks at today's observation.
  • Any model you can simulate: it handles non-linear and non-Gaussian cases at the price of random error of order 1/N1/\sqrt N1/N​.
How close to Kalman?On the Apple beta model, where Kalman is exact, a bootstrap filter with 500500500 particles differs from it by 0.0160.0160.016 on average, and with 200020002000 particles by 0.00650.00650.0065. Quadrupling the particles cut the error roughly in half, as 1/N1/\sqrt N1/N​ predicts.

Lab · what's graded

  • A particle's weight15 pts
  • The filtered mean15 pts
  • Likelihood of the observation15 pts
  • After resampling10 pts
  • Which step uses the data10 pts
  • The daily cycle10 pts
  • Match the vocabulary10 pts
  • Why particles beat Kalman here15 pts
0/ 8 answered
Tasks
1Numeric answer15 ptsNot answered

The four particles at −1,0,1,2-1,0,1,2−1,0,1,2 have likelihoods 0.054, 0.242, 0.399, 0.2420.054,\ 0.242,\ 0.399,\ 0.2420.054, 0.242, 0.399, 0.242, which sum to 0.9370.9370.937. What is the normalised weight of the particle at 111? Give three decimals.

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

The particles −1,0,1,2-1,0,1,2−1,0,1,2 have weights 0.058, 0.258, 0.426, 0.2580.058,\ 0.258,\ 0.426,\ 0.2580.058, 0.258, 0.426, 0.258. What is the filtered mean, the weighted average of the particles? Give three decimals.

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

The likelihoods of the four particles sum to 0.9370.9370.937. The filter estimates the probability of the observation as their average. What is it? Give three decimals.

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

Resampling picked the particles −1, 1, 1, 2-1,\ 1,\ 1,\ 2−1, 1, 1, 2, each now with weight 0.250.250.25. What is the mean of the new cloud?

m=m =m=accepted: ± 0.005
5Choice10 ptsNot answered

In the bootstrap filter, which step looks at today's observation?

6Order the steps10 ptsNot answered

Put the steps of one day of the bootstrap filter 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. 1Resample the cloud
  2. 2Move every particle with the model's random motion
  3. 3Take the weighted average as the estimate
  4. 4Weight each particle by the likelihood of the observation
7Match10 ptsNot answered

Match each term with its meaning.

Pick the partner of each item on the left.

Particle
Weight
Propagate
Resample
8Explain in words15 ptsNot answered

In one or two sentences, explain why a particle filter can be used when the model is non-linear or non-Gaussian, while the Kalman filter cannot.

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