σμ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
  • 日本語
  • 中文
Bayesian Inference skill›Module 3 · Models and practice›Topic 3.4·~1 hr 30 minAdvanced

Capstone: Bayesian Sharpe ratio and shrinkage on real stocks

Skill positionModule 3 of 3 · Topic 4 of 4
3.4 Capstone: Bayesian Sharpe ratio and shrinkage on real stocks
—Lab score— / 100Total XP—Streak—

How sure are you of a Sharpe ratio?

A back-test reports one Sharpe ratio, but it is estimated from noisy returns. A Bayesian estimate treats the daily mean μ and variance σ² as unknown. It starts from a weak prior and updates it with the data. The normal-inverse-gamma pair makes the update a formula with four numbers. Then you sample the posterior: draw a precision, then a mean, and turn each pair into an annual Sharpe ratio μ/σ·√252. The draws give an interval and the probability that the Sharpe ratio is above zero.

kₙ=k₀+n, mₙ=(k₀m₀+nx̄)/kₙ, aₙ=a₀+n/2, bₙ=b₀+ss/2+(k₀n(x̄-m₀)²)/2kₙ, S=μ/σ√252

The second half is about many stocks. The best-looking average returns are partly luck, so you shrink them toward the grand mean with the hierarchical rule of the last topics. The test is honest. Estimate on the first half of the years, then check how well each method predicts the average returns of the second half. You will also write your own Metropolis sampler. It is the tool for posteriors that have no formula, and here you test it on a posterior whose answer is known.

What the real data saysSPY since 2005 has a Sharpe ratio of about 0.52. The 95% credible interval runs from about 0.09 to 0.94, with a 99% chance of being above zero. Its last 250 days show 1.34, which looks wonderful, but the interval runs from about -0.66 to 3.30 and the chance of being positive is only about 91%. One year cannot separate skill from luck. For the 54 stocks, the spread of the average returns is no larger than noise alone would give, so τ²=0 and everyone is pulled to the grand mean. Predicting the second half, the raw averages have a mean squared error of about 0.0135, the shrunk ones about 0.0106: 22% lower.
  • Conjugate update: four numbers (mₙ,kₙ,aₙ,bₙ) describe the whole posterior of the mean and variance.
  • Honest error bars: a year of data gives a Sharpe interval so wide that it includes zero.
  • Shrinkage test: estimate on the first half, score on the second. Pooling beats raw averages here.
Simplifications to rememberDaily returns are treated as normal and independent, which ignores fat tails and volatility clustering. The weak prior is chosen by hand. The stock sample is survivor-biased, since it only holds large companies that existed throughout, and the stocks move together, so the study is less independent than it looks. The lesson is the method and the width of the error bars, not the exact numbers.

Lab · what's graded

  • The Sharpe ratio10 pts
  • The posterior update15 pts
  • Sharpe draws15 pts
  • A credible interval10 pts
  • Shrinking means15 pts
  • A Metropolis sampler20 pts
  • The shrinkage study15 pts
Explorer · lab-by-10
▾ lab-by-10
▾ data
…
bash · in-browser
learner@quantcraft:~/lab-by-10$
Python not loaded yetPythonLn 1, Col 1Spaces: 4UTF-8

Reset this topic?

Everything in lab-by-10 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