σμ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
  • 日本語
  • 中文
Matrix Decompositions skill›Module 5 · Factors and portfolios›Topic 5.2·~1 hr 40 minAdvanced

Capstone: a denoised covariance for minimum variance

Skill positionModule 5 of 5 · Topic 2 of 2
5.2 Capstone: a denoised covariance for minimum variance
—Lab score— / 100Total XP—Streak—

Does cleaning the matrix pay?

The minimum-variance portfolio takes a covariance matrix Σ and returns the fully invested weights with the smallest variance, w=Σ⁻¹ 1 / ( 1ᵀΣ⁻¹ 1). It looks like pure mathematics, yet it is the sharpest test of a covariance estimator, because it exploits every error in the matrix. This capstone puts the whole skill to that test. You estimate Σ from the last 63 trading days, build the portfolio, hold it for the next 21 days, then roll forward, and measure the volatility of the portfolio you would really have held. Three estimators compete: the plain sample covariance, the eigenvalue-clipped one and the Ledoit-Wolf shrunk one.

w=(Σ⁻¹ 1)/(1ᵀΣ⁻¹ 1), Σ^(*)=δμI+(1-δ)S, δ=(min(b̄²,d²))/d², λ₊=(1+√(N/T))²

Never invert the matrix: solve the linear system Σ x= 1 and divide by the sum, which is faster and more accurate. The honest part is the timing. The weights for a block of days must use only the days before it, and the result is the volatility of the joined out-of-sample returns, not the variance the optimiser promised. For clipping you work on the correlation matrix, replace the eigenvalues that are not above λ₊ by their mean, rebuild, rescale the diagonal to 1 and multiply back by the volatilities. For shrinkage you compute the intensity from the formula in the starter file, exactly as in the previous lesson, with S divided by T.

What the real data saysFor twelve large US stocks since 2010 with a 63-day window and 21-day steps (3,680 out-of-sample days), the minimum-variance portfolio built from the sample covariance has an annual volatility of about 14.3%. With the eigenvalue-clipped matrix it is about 13.9% and with Ledoit-Wolf about 13.7%, so shrinkage wins, and an equal-weight portfolio of the same stocks has about 18.4%. The gain from cleaning is a few percent of volatility with 12 assets; with hundreds of assets it is much larger, because q=N/T is then close to 1. With longer windows the three estimators get closer, and at 126 days or more clipping at the plain Marchenko-Pastur edge is slightly worse than the sample matrix, a reminder to validate every refinement out of sample.
  • Weights: solve Σ x= 1 and divide by the sum; never invert the matrix.
  • Clipping and shrinkage: noise eigenvalues to their mean; or a blend with μI with a computed intensity.
  • Backtest: estimate on the last window days, hold for step days, roll on, and measure the joined out-of-sample volatility.
The point of the whole skillA covariance matrix is an estimate, not a fact, and the people who use it, optimisers above all, are the ones who find its errors. Eigenvalues and the SVD tell you where the information in a matrix lives, the Marchenko-Pastur edge and the shrinkage intensity tell you how much of it to trust, and only a test on unseen days tells you whether your repair worked. Keep all three habits.

Lab · what's graded

  • Eigenvalue clipping25 pts
  • Ledoit-Wolf shrinkage25 pts
  • Minimum-variance weights10 pts
  • A rolling backtest20 pts
  • Comparing the estimators20 pts
Explorer · lab-md-12
▾ lab-md-12
▾ data
…
bash · in-browser
learner@quantcraft:~/lab-md-12$
Python not loaded yetPythonLn 1, Col 1Spaces: 4UTF-8

Reset this topic?

Everything in lab-md-12 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

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