σμ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 2 · The core models›Topic 2.1·~55 minIntermediate

Linear models and regularisation

Skill positionModule 2 of 4 · Topic 1 of 3
2.1 Linear models and regularisation
—Lab score— / 100Total XP—Streak—

Shrinking coefficients on purpose

Ordinary least squares finds the line that fits the training data best, and with noisy financial data it also fits the noise. Regularisation adds a penalty on the size of the coefficients, so the model gives up a little fit for a lot of stability. Ridge penalises the sum of squared coefficients and shrinks every one of them toward zero. Lasso penalises their absolute values and can push weak coefficients exactly to zero, which selects features. The strength α\alphaα is a hyperparameter: α=0\alpha=0α=0 is plain least squares and a very large α\alphaα gives a flat model that predicts the average.

b^ridge=SxySxx+α,b^lasso=max⁡(ρ−α, 0)Sxx/n,ρ=Sxyn\hat b_{\mathrm{ridge}}=\frac{S_{xy}}{S_{xx}+\alpha},\qquad \hat b_{\mathrm{lasso}}=\frac{\max(\rho-\alpha,\,0)}{S_{xx}/n},\quad \rho=\frac{S_{xy}}{n}b^ridge​=Sxx​+αSxy​​,b^lasso​=Sxx​/nmax(ρ−α,0)​,ρ=nSxy​​(1)

In practice, standardise the features inside a pipeline, because a penalty treats every coefficient alike. Choose α\alphaα on validation data that comes after the training data in time. Start with ridge when features are correlated and the signal is weak, as with momentum, value and quality scores, and use lasso when you want a short list of features. Elastic net mixes both penalties. Neither one creates signal: a penalty can only make a model less sensitive to noise.

Three points and one featureTake x=−1,0,1x=-1,0,1x=−1,0,1 and y=−1,0.5,2y=-1,0.5,2y=−1,0.5,2. Then Sxy=3S_{xy}=3Sxy​=3, Sxx=2S_{xx}=2Sxx​=2 and n=3n=3n=3. Least squares gives the slope 3/2=1.53/2=1.53/2=1.5. Ridge with α=1\alpha=1α=1 gives 3/(2+1)=1.03/(2+1)=1.03/(2+1)=1.0 and with α=2\alpha=2α=2 gives 3/4=0.753/4=0.753/4=0.75. For lasso, ρ=1\rho=1ρ=1 and Sxx/n=2/3S_{xx}/n=2/3Sxx​/n=2/3, so α=0.5\alpha=0.5α=0.5 gives 0.5/(2/3)=0.750.5/(2/3)=0.750.5/(2/3)=0.75 and α=1\alpha=1α=1 gives exactly 000. On the real monthly stock panel (16,470 rows, three standardised features) the ridge coefficients at α=1\alpha=1α=1 are about 0.00320.00320.0032 for momentum, 0.000010.000010.00001 for last month and 0.00400.00400.0040 for volatility. Because SxxS_{xx}Sxx​ is near 16,00016{,}00016,000, even α=1000\alpha=1000α=1000 shrinks a coefficient only by about 6%6\%6%, and the walk-forward information coefficient stays at 0.0330.0330.033 for every α\alphaα from 0.010.010.01 to 10410^{4}104.
  • Ridge shrinks, lasso selects: ridge keeps every feature with smaller weights, lasso can drop weak ones.
  • Strength is a trade-off: α=0\alpha=0α=0 is least squares and a huge α\alphaα predicts the average.
  • Scale the features first: a penalty treats every coefficient alike, so features must be on a common scale.

Lab · what's graded

  • Least squares10 pts
  • Ridge with alpha 115 pts
  • Ridge with alpha 215 pts
  • Lasso with alpha 0.515 pts
  • Lasso with alpha 110 pts
  • A huge penalty10 pts
  • Match the vocabulary10 pts
  • Why lasso can give exactly zero15 pts
0/ 8 answered
Tasks
1Numeric answer10 ptsNot answered

For x=−1,0,1x=-1,0,1x=−1,0,1 and y=−1,0.5,2y=-1,0.5,2y=−1,0.5,2 we have Sxy=3S_{xy}=3Sxy​=3 and Sxx=2S_{xx}=2Sxx​=2. What is the least-squares slope Sxy/SxxS_{xy}/S_{xx}Sxy​/Sxx​?

b=b =b=accepted: ± 0.01
2Numeric answer15 ptsNot answered

Ridge shrinks the slope to Sxy/(Sxx+α)S_{xy}/(S_{xx}+\alpha)Sxy​/(Sxx​+α). With Sxy=3S_{xy}=3Sxy​=3, Sxx=2S_{xx}=2Sxx​=2 and α=1\alpha=1α=1, what is the ridge slope?

b=b =b=accepted: ± 0.01
3Numeric answer15 ptsNot answered

Now take α=2\alpha=2α=2 with the same Sxy=3S_{xy}=3Sxy​=3 and Sxx=2S_{xx}=2Sxx​=2. What is the ridge slope? Give two decimals.

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

For the same data ρ=Sxy/n=1\rho=S_{xy}/n=1ρ=Sxy​/n=1 and Sxx/n=2/3S_{xx}/n=2/3Sxx​/n=2/3. The lasso slope is max⁡(ρ−α,0)/(Sxx/n)\max(\rho-\alpha,0)/(S_{xx}/n)max(ρ−α,0)/(Sxx​/n). What is it for α=0.5\alpha=0.5α=0.5? Give two decimals.

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

With the same data and α=1\alpha=1α=1, what is the lasso slope max⁡(ρ−α,0)/(Sxx/n)\max(\rho-\alpha,0)/(S_{xx}/n)max(ρ−α,0)/(Sxx​/n)?

b=b =b=accepted: ± 0.005
6Choice10 ptsNot answered

A ridge model is fitted with a very large alpha. What does it predict?

7Match10 ptsNot answered

Match each model with how it treats coefficients.

Pick the partner of each item on the left.

Least squares
Ridge
Lasso
Alpha
8Explain in words15 ptsNot answered

In one or two sentences, explain why lasso can set a coefficient exactly to zero while ridge only makes it smaller.

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