σμ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
  • 日本語
  • 中文
statsmodels skill›Module 1 · Regression and its checks›Topic 1.6·~50 minIntermediate

Robust standard errors with Newey–West

Skill positionModule 1 of 3 · Topic 6 of 8
1.6 Robust standard errors with Newey–West
—Lab score— / 100Total XP—Streak—

When neighbouring errors are linked

Ordinary standard errors assume every observation brings new information. Financial data often breaks that. Returns measured over three months and sampled every month overlap, so each observation shares two months with its neighbour, and the errors move together. The same happens when volatility clusters. The fix keeps the coefficients and changes only the standard errors. The Newey–West estimator, also called HAC for heteroskedasticity and autocorrelation consistent, estimates the long-run variance by adding the lagged autocovariances γℓ\gamma_\ellγℓ​ of the residuals, each multiplied by a Bartlett weight 1−ℓ/(L+1)1-\ell/(L+1)1−ℓ/(L+1) that shrinks to zero at the cut-off lag LLL. In statsmodels you only add cov_type='HAC' and cov_kwds={'maxlags': L} to .fit().

ω^=γ^0+2∑ℓ=1L(1−ℓL+1)γ^ℓ,γ^ℓ=1n∑t=ℓ+1netet−ℓ,se(zˉ)=ω^/n,L≈⌊4(n100)2/9⌋\hat\omega=\hat\gamma_0+2\sum_{\ell=1}^{L}\Bigl(1-\frac{\ell}{L+1}\Bigr)\hat\gamma_\ell,\qquad \hat\gamma_\ell=\frac1n\sum_{t=\ell+1}^{n}e_te_{t-\ell},\qquad \mathrm{se}(\bar z)=\sqrt{\hat\omega/n},\qquad L\approx\Bigl\lfloor4\Bigl(\frac{n}{100}\Bigr)^{2/9}\Bigr\rfloorω^=γ^​0​+2ℓ=1∑L​(1−L+1ℓ​)γ^​ℓ​,γ^​ℓ​=n1​t=ℓ+1∑n​et​et−ℓ​,se(zˉ)=ω^/n​,L≈⌊4(100n​)2/9⌋(1)
A five-number seriesTake z=3,3,2,1,1z=3,3,2,1,1z=3,3,2,1,1 with mean 222 and deviations 1,1,0,−1,−11,1,0,-1,-11,1,0,−1,−1. Then γ^0=4/5=0.8\hat\gamma_0=4/5=0.8γ^​0​=4/5=0.8 and γ^1=(1+0+0+1)/5=0.4\hat\gamma_1=(1+0+0+1)/5=0.4γ^​1​=(1+0+0+1)/5=0.4, positive because neighbours are alike. With L=1L=1L=1 the Bartlett weight is 1−1/2=0.51-1/2=0.51−1/2=0.5, so ω^=0.8+2⋅0.5⋅0.4=1.2\hat\omega=0.8+2\cdot0.5\cdot0.4=1.2ω^=0.8+2⋅0.5⋅0.4=1.2 and se=1.2/5=0.490\mathrm{se}=\sqrt{1.2/5}=0.490se=1.2/5​=0.490. The ordinary standard error is 1/5=0.447\sqrt{1/5}=0.4471/5​=0.447 (using s2=SSE/(n−1)=1s^2=\mathrm{SSE}/(n-1)=1s2=SSE/(n−1)=1), so the t-statistic of the mean falls from 2/0.447=4.472/0.447=4.472/0.447=4.47 to 2/0.490=4.082/0.490=4.082/0.490=4.08. When the autocorrelation is negative the standard error shrinks instead.

Real data shows the size of the effect. The average 3-month return of SPY, sampled monthly, is 2.78%2.78\%2.78% over 256256256 overlapping observations. Ordinary standard errors give 0.456%0.456\%0.456% and t=6.10t=6.10t=6.10. The autocorrelations of the demeaned series are 0.680.680.68, 0.350.350.35 and 0.080.080.08 at lags 111, 222 and 333, the triangle that overlap of two months out of three creates. With Newey–West at L=2L=2L=2 the standard error is 0.664%0.664\%0.664% (t=4.18t=4.18t=4.18), at L=4L=4L=4 it is 0.732%0.732\%0.732% (t=3.80t=3.80t=3.80) and at L=6L=6L=6 it is 0.762%0.762\%0.762% (t=3.65t=3.65t=3.65), and the 868686 non-overlapping quarters give t=3.55t=3.55t=3.55. In a monthly three-factor regression for Apple (319319319 months) the change is smaller but real: the standard error of the value loading rises from 0.1440.1440.144 to 0.1700.1700.170, so its t-statistic moves from −4.98-4.98−4.98 to −4.22-4.22−4.22.

  • Same coefficients, new standard errors: HAC changes only the uncertainty, never the estimate.
  • Overlap sets the lag: with hhh-month returns sampled monthly, use at least L=h−1L=h-1L=h−1 and often a few more.
  • Report the honest t: a t of 6 can be a t of 4 once neighbouring errors are accounted for.

Lab · what's graded

  • The variance term10 pts
  • The first autocovariance10 pts
  • The long-run variance15 pts
  • The HAC standard error15 pts
  • The robust t-statistic10 pts
  • The statsmodels call10 pts
  • Match the vocabulary10 pts
  • Why the ordinary t is too big20 pts
0/ 8 answered
Tasks
1Numeric answer10 ptsNot answered

The deviations from the mean are 1,1,0,−1,−11,1,0,-1,-11,1,0,−1,−1. What is γ^0=1n∑et2\hat\gamma_0=\frac1n\sum e_t^2γ^​0​=n1​∑et2​? Give one decimal.

g0=g0 =g0=accepted: ± 0.01
2Numeric answer10 ptsNot answered

With the same deviations, what is γ^1=1n∑t=2netet−1\hat\gamma_1=\frac1n\sum_{t=2}^{n}e_te_{t-1}γ^​1​=n1​∑t=2n​et​et−1​? Give one decimal.

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

With L=1L=1L=1 the Bartlett weight is 0.50.50.5. Using γ^0=0.8\hat\gamma_0=0.8γ^​0​=0.8 and γ^1=0.4\hat\gamma_1=0.4γ^​1​=0.4, what is ω^=γ^0+2⋅0.5⋅γ^1\hat\omega=\hat\gamma_0+2\cdot0.5\cdot\hat\gamma_1ω^=γ^​0​+2⋅0.5⋅γ^​1​? Give one decimal.

w=w =w=accepted: ± 0.02
4Numeric answer15 ptsNot answered

With ω^=1.2\hat\omega=1.2ω^=1.2 and n=5n=5n=5, what is se(zˉ)=ω^/n\mathrm{se}(\bar z)=\sqrt{\hat\omega/n}se(zˉ)=ω^/n​? Use 0.24=0.4899\sqrt{0.24}=0.48990.24​=0.4899 and give three decimals.

se=se =se=accepted: ± 0.004
5Numeric answer10 ptsNot answered

The mean of the series is 222 and its HAC standard error is 0.4900.4900.490. What is the t-statistic? Give two decimals.

t=t =t=accepted: ± 0.03
6Choice10 ptsNot answered

Which call fits the model with Newey–West standard errors using 3 lags?

7Match10 ptsNot answered

Match each term with its meaning.

Pick the partner of each item on the left.

HAC
Bartlett weight
maxlags
Overlapping returns
8Explain in words20 ptsNot answered

The mean 3-month return has t=6.10t=6.10t=6.10 with ordinary errors and t=3.80t=3.80t=3.80 with Newey–West at L=4L=4L=4. In one or two sentences, explain why overlapping returns make the ordinary ttt too large.

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