σμ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 1 · The estimator way of working›Topic 1.3·~50 minIntermediate

Splits and leakage in finance

Skill positionModule 1 of 4 · Topic 3 of 5
1.3 Splits and leakage in finance
—Lab score— / 100Total XP—Streak—

Why the split is the whole game

A model is judged on data it has not seen. In finance there are three sets: training data to fit, validation data to choose settings and test data, used once, to report the result. They must follow time: train on the past, validate on the next stretch, test on the last one. A random split puts days from the same storm in both sets, so the model recognises neighbours instead of learning a rule. Leakage means that information from the validation or test period reaches the training step. It comes in four common forms: a scaler fitted on all days, a feature that uses a future price, a target-like column that is known only afterwards, and labels that overlap in time.

Overlapping labels deserve special care. If the label is the return over the next HHH months, the label of a training row iii and of a test row jjj share months whenever i+H>ji+H>ji+H>j. The last H−1H-1H−1 training rows before the test period therefore know part of the test outcome. The cure is purging, which drops those rows, and an embargo, which keeps a safety gap, as the next topics show. A small number shows the size of the problem: with 100010001000 monthly rows, a 60/20/2060/20/2060/20/20 split puts the test period at row 800800800, and for H=3H=3H=3 two training rows near each boundary overlap.

(i, i+H]∩(j, j+H]≠∅  ⟺  i+H>j(i<j)(i,\,i+H]\cap(j,\,j+H]\neq\varnothing\iff i+H>j\qquad(i<j)(i,i+H]∩(j,j+H]=∅⟺i+H>j(i<j)(1)
Numbers and a real exampleIf the training values are 2,4,6,82,4,6,82,4,6,8 the scaler learns mean 555. Fitted on all days including a test value 202020, it would learn mean 888, a gap of 333 that came from the future. In real data, take SPY and ask a random forest to predict the next 202020 days of volatility from recent volatility. A shuffled 5-fold split gives R2=0.60R^{2}=0.60R2=0.60. A time-ordered walk-forward split with a 202020-day purge gives R2=−2.10R^{2}=-2.10R2=−2.10. The shuffled score is higher by 2.702.702.70 because neighbouring days share 191919 of their 202020 label days, and because a time-ordered test has to face storms that it has not seen.
  • Split by time: train on the past, validate on the next stretch, test on the last, and look at the test once.
  • Four leaks: fitted preprocessing, future features, target-like columns and overlapping labels.
  • A shuffled score is a warning sign: if shuffling the days raises the score a lot, the model is recognising neighbours.

Lab · what's graded

  • Where the test period starts10 pts
  • The training size10 pts
  • What the scaler learns from the future10 pts
  • Overlapping labels15 pts
  • How much a shuffle flatters10 pts
  • The right split for a time series10 pts
  • A leak-free workflow10 pts
  • Kinds of leakage10 pts
  • Why shuffling inflates the score15 pts
0/ 9 answered
Tasks
1Numeric answer10 ptsNot answered

There are 100010001000 monthly rows in time order, split 60%60\%60% training, 20%20\%20% validation and 20%20\%20% test. At which row index (counting from 000) does the test period start?

i=i =i=accepted: ± 0.5
2Numeric answer10 ptsNot answered

With the same split of 100010001000 rows, how many rows are in the training set?

n=n =n=accepted: ± 0.5
3Numeric answer10 ptsNot answered

The training values are 2,4,6,82,4,6,82,4,6,8 (mean 555) and the test value is 202020. A scaler fitted on all five values learns a mean of 888. By how much does the mean differ from the honest one?

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

The label of row iii is the return over the next H=3H=3H=3 months. A training row iii and the first test row j=600j=600j=600 share months when i+H>ji+H>ji+H>j. How many training rows i<600i<600i<600 overlap the label of row 600600600?

k=k =k=accepted: ± 0.01
5Numeric answer10 ptsNot answered

On SPY, a random forest predicting the next 202020 days of volatility gets R2=0.60R^{2}=0.60R2=0.60 with a shuffled split and R2=−2.10R^{2}=-2.10R2=−2.10 with a purged walk-forward split. By how much does the shuffle flatter it? Give two decimals.

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

You want to judge a daily return model honestly. Which split do you use?

7Order the steps10 ptsNot answered

Put the steps of a leak-free evaluation 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. 1Look at the test score once and report it
  2. 2Order the rows by time and cut train, validation and test
  3. 3Choose the settings with the validation data
  4. 4Fit preprocessing and model on the training data
8Match10 ptsNot answered

Match each kind of leakage with its example.

Pick the partner of each item on the left.

Preprocessing leak
Look-ahead feature
Target leak
Label overlap
9Explain in words15 ptsNot answered

In one or two sentences, explain why a shuffled split gives a better score than a time-ordered split when the target is a return over the next 202020 days.

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