σμ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 1 · Beliefs and evidence›Topic 1.4·~1 hrIntermediate

Bayesian linear regression

Skill positionModule 1 of 3 · Topic 4 of 4
1.4 Bayesian linear regression
—Lab score— / 100Total XP—Streak—

Regression with honest uncertainty

Ordinary regression gives you one slope. Bayesian regression gives you a whole distribution for the slope. Take a stock's return yyy and the market's return xxx with y=βx+ey=\beta x+ey=βx+e, and let the noise eee have variance σ2\sigma^{2}σ2. Start with a prior for the beta, for example a normal centred on m0=1m_0=1m0​=1 with variance v0v_0v0​. The data push the slope toward the least-squares value and the prior pulls it back. It is the same precision-weighted average as in the last topics. The prior precision is 1/v01/v_01/v0​, the data precision is ∑x2/σ2\sum x^{2}/\sigma^{2}∑x2/σ2, and the second one is large when the market moved a lot.

Pn=1v0+∑x2σ2,mn=m0/v0+∑xy/σ2Pn,sd(β)=1PnP_n=\frac{1}{v_0}+\frac{\sum x^{2}}{\sigma^{2}},\qquad m_n=\frac{m_0/v_0+\sum xy/\sigma^{2}}{P_n},\qquad \mathrm{sd}(\beta)=\frac{1}{\sqrt{P_n}}Pn​=v0​1​+σ2∑x2​,mn​=Pn​m0​/v0​+∑xy/σ2​,sd(β)=Pn​​1​(1)

Two things are worth noting. First, a prior centred on 000 gives exactly ridge regression: the slope is ∑xy / (∑x2+λ)\sum xy\,/\,(\sum x^{2}+\lambda)∑xy/(∑x2+λ) with λ=σ2/v0\lambda=\sigma^{2}/v_0λ=σ2/v0​. So ridge regression is just a Bayesian regression whose prior distrusts large slopes. Second, a prediction for a new x∗x^{*}x∗ has two sources of spread: the noise σ2\sigma^{2}σ2 and the uncertainty of the slope, which adds x∗2/Pnx^{*2}/P_nx∗2/Pn​. The second part grows with the square of x∗x^{*}x∗, so predictions far from the data are less certain.

A beta with numbersSay ∑x2=40\sum x^{2}=40∑x2=40, ∑xy=48\sum xy=48∑xy=48 and σ2=4\sigma^{2}=4σ2=4. The least-squares slope is 48/40=1.248/40=1.248/40=1.2. With the prior N(1, 0.52)N(1,\,0.5^{2})N(1,0.52), so v0=0.25v_0=0.25v0​=0.25: the precision is 4+40/4=144+40/4=144+40/4=14, the mean is (4+12)/14=1.143(4+12)/14=1.143(4+12)/14=1.143 and the standard deviation is 1/14=0.2671/\sqrt{14}=0.2671/14​=0.267. With a ridge prior centred on 000 the slope would be 48/(40+16)=0.85748/(40+16)=0.85748/(40+16)=0.857. A prediction at x∗=2x^{*}=2x∗=2 has mean 2.292.292.29 and standard deviation 4+4/14=2.07\sqrt{4+4/14}=2.074+4/14​=2.07.
  • Bayesian slope: a distribution whose precision is the prior precision plus the data precision.
  • Ridge regression is the case of a prior centred on 000, with λ=σ2/v0\lambda=\sigma^{2}/v_0λ=σ2/v0​.
  • Predictions carry noise plus slope uncertainty, and the second part grows with x∗2x^{*2}x∗2.

Lab · what's graded

  • The posterior precision15 pts
  • The posterior slope15 pts
  • The slope's uncertainty10 pts
  • The ridge slope15 pts
  • A prediction's spread10 pts
  • A very confident prior10 pts
  • Match the vocabulary10 pts
  • Far from the data15 pts
0/ 8 answered
Tasks
1Numeric answer15 ptsNot answered

With ∑x2=40\sum x^{2}=40∑x2=40, σ2=4\sigma^{2}=4σ2=4 and prior variance v0=0.25v_0=0.25v0​=0.25, what is the posterior precision 1/v0+∑x2/σ21/v_0+\sum x^{2}/\sigma^{2}1/v0​+∑x2/σ2?

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

Now add the prior mean m0=1m_0=1m0​=1 and ∑xy=48\sum xy=48∑xy=48. What is the posterior mean (m0/v0+∑xy/σ2)/14\big(m_0/v_0+\sum xy/\sigma^{2}\big)/14(m0​/v0​+∑xy/σ2)/14? Give four decimals.

m=m =m=accepted: ± 0.001
3Numeric answer10 ptsNot answered

What is the posterior standard deviation of the slope, 1/141/\sqrt{14}1/14​? Give four decimals.

s=s =s=accepted: ± 0.001
4Numeric answer15 ptsNot answered

Use a prior centred on 000 with v0=0.25v_0=0.25v0​=0.25 and σ2=4\sigma^{2}=4σ2=4, so λ=σ2/v0=16\lambda=\sigma^{2}/v_0=16λ=σ2/v0​=16. What is the ridge slope ∑xy / (∑x2+λ)\sum xy\,/\,(\sum x^{2}+\lambda)∑xy/(∑x2+λ) with ∑xy=48\sum xy=48∑xy=48 and ∑x2=40\sum x^{2}=40∑x2=40? Give four decimals.

r=r =r=accepted: ± 0.001
5Numeric answer10 ptsNot answered

For a new x∗=2x^{*}=2x∗=2 the predictive standard deviation is σ2+x∗2/14\sqrt{\sigma^{2}+x^{*2}/14}σ2+x∗2/14​ with σ2=4\sigma^{2}=4σ2=4. What is it? Give three decimals.

p=p =p=accepted: ± 0.01
6Choice10 ptsNot answered

What happens to the posterior slope if the prior variance v0v_0v0​ becomes very small?

7Match10 ptsNot answered

Match each term with its meaning.

Pick the partner of each item on the left.

Least-squares slope
Ridge regression
Posterior precision
Predictive variance
8Explain in words15 ptsNot answered

In one or two sentences, explain why a Bayesian regression gives wider prediction ranges for xxx values far from the data.

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