σμ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
  • 日本語
  • 中文
Statistics skill›Module 4 · Validation and overfitting›Topic 4.1·~55 minIntermediate

Cross-validation and overfitting

Skill positionModule 4 of 4 · Topic 1 of 3
4.1 Cross-validation and overfitting
—Lab score— / 100Total XP—Streak—

Fitting the past is easy

Give a model enough freedom and it will fit any training data, noise included. That is overfitting: a great in-sample fit that collapses on new data. Underfitting is the opposite, a model too simple to capture the pattern. The cure for both is to judge a model on data it has not seen. The in-sample R2R^2R2 never goes down when you add predictors, so it rewards overfitting, while the adjusted R2=1−(1−R2)n−1n−p−1R^2=1-(1-R^2)\frac{n-1}{n-p-1}R2=1−(1−R2)n−p−1n−1​ penalises each extra predictor.

CV⁡k=1k∑j=1kErr⁡j\operatorname{CV}_k=\frac{1}{k}\sum_{j=1}^{k}\operatorname{Err}_jCVk​=k1​j=1∑k​Errj​(1)

kkk-fold cross-validation splits the data into kkk folds, trains on k−1k-1k−1 of them, scores on the held-out fold and averages the kkk scores. A separate test set, touched once at the very end, gives the final honest estimate; the validation folds are used up by choices such as the penalty λ\lambdaλ. With time series, shuffling is wrong: a random split trains on days after the ones it tests, which leaks the future. Use walk-forward validation instead, always training on the past and testing on the block that follows, optionally with a gap to avoid overlap in labels.

Counting folds and penalising predictorsWith 1,000 observations and 5 folds, each fold holds 200, so each model trains on 800 and tests on 200. A regression with n=50n=50n=50 and p=10p=10p=10 predictors has R2=0.40R^2=0.40R2=0.40; the adjusted value is 1−0.6⋅4939≈0.2461-0.6\cdot\frac{49}{39}\approx0.2461−0.6⋅3949​≈0.246, much lower. In walk-forward validation, train on years 1-3, test on year 4; train on years 1-4, test on year 5; and so on. Averaging the out-of-sample scores gives a more honest picture than any in-sample fit.
  • Overfitting: great on training data, poor on new data. Underfitting: poor on both.
  • Cross-validation: train on some folds, score on the held-out one, average; keep a test set for the end.
  • Time series: never shuffle; train on the past, test on the future block (walk-forward).
Leakage is silentAny step that uses information from the test period before the test is leakage, and it inflates results without any error message. Scaling features with the full-sample mean, choosing features on all the data before splitting, or using tomorrow's price as a feature all qualify. Fit every transformation inside the training fold only, and apply it to the test fold unchanged.

Lab · what's graded

  • The size of a training set10 pts
  • Why not shuffle15 pts
  • A walk-forward test15 pts
  • An adjusted R squared15 pts
  • The vocabulary15 pts
  • Spot the leakage15 pts
  • Why in-sample fit says little15 pts
0/ 7 answered
Tasks
1Numeric answer10 ptsNot answered

In 5-fold cross-validation on 1,000 observations, how many observations does each model train on?

n=n =n=accepted: ± 0.1%
2Choice15 ptsNot answered

Why is random k-fold cross-validation a poor choice for daily return data?

3Order the steps15 ptsNot answered

Put the steps of a walk-forward validation 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. 1Move the window forward by one block
  2. 2Fit the model on an initial window of the past
  3. 3Repeat, then average the out-of-sample scores
  4. 4Score it on the next block, which it has not seen
4Numeric answer15 ptsNot answered

A regression with n = 50 observations and p = 10 predictors has R squared = 0.40. Compute the adjusted R squared, 1 - (1 - R^2)(n - 1)/(n - p - 1). Give it to four decimals.

Rˉ2=\bar R^{2} =Rˉ2=accepted: ± 0.001
5Match15 ptsNot answered

Match each term to its meaning.

Pick the partner of each item on the left.

Overfitting
Underfitting
Validation set
Test set
6Choice15 ptsNot answered

Select every step that leaks information from the test period.

7Explain in words15 ptsNot answered

In two sentences, say why a high in-sample fit is weak evidence that a model will work on new data.

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