σμ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 3 · Cross-sections and tails›Topic 3.1·~45 minAdvanced

Quantile regression for tail risk

Skill positionModule 3 of 3 · Topic 1 of 3
3.1 Quantile regression for tail risk
—Lab score— / 100Total XP—Streak—

Modelling the edges, not the middle

Least squares models the average. Risk lives in the tails: a stock's worst days may react to a variable that hardly moves its average day. Quantile regression fits a chosen quantile τ\tauτ of the response directly, for example the 5% quantile that a value-at-risk limit is built on. It does this by minimising the check (pinball) loss ρτ(u)=u (τ−1[u<0])\rho_\tau(u)=u\,(\tau-\mathbf 1[u<0])ρτ​(u)=u(τ−1[u<0]) over the residuals u=y−qu=y-qu=y−q. Positive residuals are weighted by τ\tauτ and negative ones by 1−τ1-\tau1−τ, so for τ=0.9\tau=0.9τ=0.9 a guess that is too low costs nine times more than one that is too high, which pushes the guess up to the 90th percentile. For τ=0.5\tau=0.5τ=0.5 the loss is half the absolute error and the minimiser is the median. In statsmodels you write smf.quantreg('y ~ vol', data).fit(q=0.05).

ρτ(u)=u (τ−1[u<0]),β^τ=arg⁡min⁡β∑iρτ(yi−xi⊤β),Qτ(y∣x)=x⊤βτ\rho_\tau(u)=u\,(\tau-\mathbf 1[u<0]),\qquad \hat\beta_\tau=\arg\min_\beta\sum_i\rho_\tau(y_i-x_i^{\top}\beta),\qquad Q_\tau(y\mid x)=x^{\top}\beta_\tauρτ​(u)=u(τ−1[u<0]),β^​τ​=argβmin​i∑​ρτ​(yi​−xi⊤​β),Qτ​(y∣x)=x⊤βτ​(1)
Loss by hand and a value-at-risk lineTake y=1,2,3,10,20y=1,2,3,10,20y=1,2,3,10,20. The median 333 has absolute loss 2+1+0+7+17=272+1+0+7+17=272+1+0+7+17=27, while the mean 7.27.27.2 has 31.231.231.2. For τ=0.9\tau=0.9τ=0.9 and the guess q=10q=10q=10 the residuals are −9,−8,−7,0,10-9,-8,-7,0,10−9,−8,−7,0,10 and the loss is 0.1(9+8+7)+0.9⋅10=11.40.1(9+8+7)+0.9\cdot10=11.40.1(9+8+7)+0.9⋅10=11.4, while the guess q=20q=20q=20 costs only 0.1(19+18+17+10)=6.40.1(19+18+17+10)=6.40.1(19+18+17+10)=6.4, because four of five points sit below it, which is what a 90% quantile should look like. Now use real data: SPY's next-day return in percent against the volatility of the past 20 days (also in percent), 5,3845{,}3845,384 days. Least squares finds almost no effect, with a slope of 0.0110.0110.011. Quantile regression finds a slope of −1.50-1.50−1.50 at τ=0.05\tau=0.05τ=0.05 (standard error 0.050.050.05) and +1.37+1.37+1.37 at τ=0.95\tau=0.95τ=0.95, and 0.030.030.03 at the median. At volatility 1%1\%1% the fitted quantiles are −1.77%-1.77\%−1.77%, 0.07%0.07\%0.07% and 1.64%1.64\%1.64%, and at 2%2\%2% they are −3.27%-3.27\%−3.27%, 0.10%0.10\%0.10% and 3.01%3.01\%3.01%: a band of width 6.286.286.28 points. The tails open up with volatility while the centre barely moves. As a value-at-risk limit the fitted τ=0.05\tau=0.05τ=0.05 line is breached on 5.0%5.0\%5.0% of days overall, and on 7.2%7.2\%7.2% of the 263263263 days with volatility above 2%2\%2%, where the constant normal limit of −1.92%-1.92\%−1.92% is breached on 22.4%22.4\%22.4% and on only 1.3%1.3\%1.3% of the 2,6002{,}6002,600 calm days below 0.8%0.8\%0.8%.

Two cautions. Quantile lines fitted separately can cross, so the 5% line ends above the 50% line in the extremes of xxx, which a careful analyst checks. And the standard errors of quantile regression are bootstrapped or asymptotic, with the same autocorrelation worries as before, so tail estimates from short samples are noisy.

  • Pick the quantile you care about: 5% for downside risk, 50% for the typical case, 95% for the upside.
  • Check coverage by regime: a limit that is right overall can be wrong in every calm and every stormy period.

Lab · what's graded

  • An absolute loss15 pts
  • A pinball loss15 pts
  • A predicted 5% quantile15 pts
  • The width of the band10 pts
  • Expected breaches15 pts
  • Why the constant limit fails10 pts
  • The average hides the tail20 pts
0/ 7 answered
Tasks
1Numeric answer15 ptsNot answered

For y=1,2,3,10,20y=1,2,3,10,20y=1,2,3,10,20 and the guess q=3q=3q=3 (the median), what is ∑∣yi−q∣\sum|y_i-q|∑∣yi​−q∣?

l1=l1 =l1=accepted: ± 0.1
2Numeric answer15 ptsNot answered

For τ=0.9\tau=0.9τ=0.9 and the guess q=10q=10q=10 the residuals y−qy-qy−q are −9,−8,−7,0,10-9,-8,-7,0,10−9,−8,−7,0,10. Negative residuals cost 0.10.10.1 per unit and positive ones 0.90.90.9 per unit. What is the total loss? Give one decimal.

pin=pin =pin=accepted: ± 0.05
3Numeric answer15 ptsNot answered

The fitted 5% line is −0.277−1.495⋅v-0.277-1.495\cdot v−0.277−1.495⋅v, with the 20-day volatility in percent. What is the 5% quantile of tomorrow's return when the volatility is 1.51.51.5? Give two decimals.

v=v =v=accepted: ± 0.02
4Numeric answer10 ptsNot answered

At volatility 2%2\%2% the fitted 5% and 95% quantiles are −3.27-3.27−3.27 and 3.013.013.01. How wide is the band between them? Give two decimals.

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

A correct 5% limit should be breached on 5%5\%5% of days. Among the 263263263 days with volatility above 2%2\%2%, how many breaches should you expect? Give one decimal.

n=n =n=accepted: ± 0.1
6Choice10 ptsNot answered

A constant normal limit of -1.92% is breached on 22.4% of high-volatility days and 1.3% of calm days. Why?

7Explain in words20 ptsNot answered

Least squares gives a slope of 0.0110.0110.011 for next-day return on volatility, while the 5% quantile slope is −1.50-1.50−1.50. In one or two sentences, explain how both can be true.

Math modeKeyboard or LaTeX inputTask 1 of 7 · 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