σμ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
  • 日本語
  • 中文
scikit-learn skill›Module 3 · Honest evaluation›Topic 3.5·~1 hrAdvanced

A purged and embargoed splitter

Skill positionModule 3 of 4 · Topic 5 of 9
3.5 A purged and embargoed splitter
—Lab score— / 100Total XP—Streak—
Lecture0% read

2 min read

01

When neighbours share a label

Suppose the label of day t is the return from the close of day t to the close of day t+h, with h=5. Then the labels of day t and day t+1 share four of their five daily returns: they are almost the same number. A K-fold that puts day t in the training set and day t+1 in the test set lets the model see the answer it is being tested on. A flexible model, such as nearest neighbours, then looks skilful just by remembering. The leak has a precise shape: the label of row i is only known at row i+h, so row i overlaps a test block [t₀,t₁] when i+h≥t₀ and i≤t₁.

Purging drops every training row that overlaps the test block. The embargo drops a few more rows just after the block, because slow features such as a 20-day return keep carrying information forward. A splitter for scikit-learn is any object with split(X), which yields (train, test) index arrays, and get_n_splits(); it can then be passed as cv= to cross_val_score or GridSearchCV. On 5,340 days of SPY with four slow features and a five-day label, a nearest-neighbours model has an R squared of 0.039 under shuffled folds and -0.36 under purged folds. The model has no skill, and the shuffled number is the leak speaking. A plain unshuffled K-fold is much better, but it still has 120 overlapping pairs at the four boundaries; the purged splitter has none.

  • Overlapping labels put near-copies on both sides of a split; shuffled K-fold then rewards memory.
  • Purge rows with i+h≥t₀ and i≤t₁; embargo a few rows after t₁.
  • A splitter is just split and get_n_splits: any object with both works as cv=.

Lab · what's graded

5 tasks · 100 pts
  • Purge and embargo25 pts
  • The splitter25 pts
  • The scorer10 pts
  • Counting overlaps15 pts
  • The leakage study25 pts
Explorer · lab-sl-19
▾ lab-sl-19
▾ data
…
bash · in-browser
learner@quantcraft:~/lab-sl-19$
Python not loaded yetPythonLn 1, Col 1Spaces: 4UTF-8

Reset this topic?

Everything in lab-sl-19 goes back to the starter files and the terminal is cleared. Your current solution will be lost — this can't be undone.

Will be reset
  • main.py → starter code
  • Terminal history and test output
  • Unsubmitted changes
Will be kept
  • Best lab score
  • Your XP and streak
  • Lecture progress and notes