σμ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.8·~45 minIntermediate

Logit and probit models

Skill positionModule 1 of 3 · Topic 8 of 8
1.8 Logit and probit models
—Lab score— / 100Total XP—Streak—

Modelling a yes or no

Some outcomes are not numbers but events: the market closed up or down, a stock was in the top half, a firm defaulted. A straight line cannot model a probability because it can leave the range 0 to 1. Logit and probit squeeze a linear score z=α+βxz=\alpha+\beta xz=α+βx through an S-shaped curve. The logit uses p=1/(1+e−z)p=1/(1+e^{-z})p=1/(1+e−z), so the score is the log-odds ln⁡p1−p\ln\frac{p}{1-p}ln1−pp​. The probit uses the normal distribution function p=Φ(z)p=\Phi(z)p=Φ(z). They give nearly the same probabilities, and the probit coefficients are about 1/1.61/1.61/1.6 of the logit ones. In statsmodels you write smf.logit('up ~ lag', data).fit(), and the model is estimated by maximum likelihood, not by least squares: it picks the coefficients that make the observed ups and downs most probable.

p=11+e−z,ln⁡p1−p=α+βx,∂p∂x=p(1−p)β,ℓ=∑i[yiln⁡pi+(1−yi)ln⁡(1−pi)],RMcF2=1−ℓℓ0p=\frac{1}{1+e^{-z}},\qquad \ln\frac{p}{1-p}=\alpha+\beta x,\qquad \frac{\partial p}{\partial x}=p(1-p)\beta,\qquad \ell=\sum_i\bigl[y_i\ln p_i+(1-y_i)\ln(1-p_i)\bigr],\qquad R^{2}_{\mathrm{McF}}=1-\frac{\ell}{\ell_0}p=1+e−z1​,ln1−pp​=α+βx,∂x∂p​=p(1−p)β,ℓ=i∑​[yi​lnpi​+(1−yi​)ln(1−pi​)],RMcF2​=1−ℓ0​ℓ​(1)
Reading a logit by handA score z=0.2z=0.2z=0.2 gives p=1/(1+e−0.2)=1/1.8187=0.55p=1/(1+e^{-0.2})=1/1.8187=0.55p=1/(1+e−0.2)=1/1.8187=0.55. A slope β=−0.054\beta=-0.054β=−0.054 means the odds are multiplied by e−0.054=0.947e^{-0.054}=0.947e−0.054=0.947 for each extra unit of xxx. The effect on the probability itself depends on where you are: at p=0.55p=0.55p=0.55 it is p(1−p)β=0.55⋅0.45⋅(−0.054)=−0.0134p(1-p)\beta=0.55\cdot0.45\cdot(-0.054)=-0.0134p(1−p)β=0.55⋅0.45⋅(−0.054)=−0.0134, the marginal effect. The likelihood adds up log-probabilities of what happened: for predicted ups 0.8,0.3,0.60.8,0.3,0.60.8,0.3,0.6 and outcomes 1,0,11,0,11,0,1 the log-likelihood is ln⁡0.8+ln⁡0.7+ln⁡0.6=−1.09\ln0.8+\ln0.7+\ln0.6=-1.09ln0.8+ln0.7+ln0.6=−1.09. McFadden's pseudo R-squared compares with a model that has only an intercept: if that model has ℓ0=−69.3\ell_0=-69.3ℓ0​=−69.3 and yours ℓ=−60\ell=-60ℓ=−60, then 1−60/69.3=0.1341-60/69.3=0.1341−60/69.3=0.134.

Real data keeps the lesson honest. For SPY over 5,4035{,}4035,403 trading days since 2005, 54.86%54.86\%54.86% of days closed up. A logit of the next-day direction on today's return, in percent, gives α^=0.198\hat\alpha=0.198α^=0.198 and β^=−0.054\hat\beta=-0.054β^​=−0.054 with z=−2.34z=-2.34z=−2.34 (p=0.019p=0.019p=0.019): after a 2%2\%2% fall the chance of an up day is 57.6%57.6\%57.6%, after a flat day 54.9%54.9\%54.9% and after a 2%2\%2% rise 52.2%52.2\%52.2%. The marginal effect is −0.0134-0.0134−0.0134 and the probit agrees (β^=−0.034\hat\beta=-0.034β^​=−0.034, marginal effect −0.0134-0.0134−0.0134, same log-likelihood −3716.76-3716.76−3716.76). Yet McFadden's R2R^2R2 is 0.00070.00070.0007, and predicting up whenever the probability exceeds one half is right on 54.97%54.97\%54.97% of days against 54.86%54.86\%54.86% for always saying up. A coefficient can be statistically detectable and still be useless for trading.

  • Probabilities need a curve: logit and probit keep the fitted chance between 0 and 1, and they agree closely.
  • Coefficients are log-odds: exponentiate for an odds ratio, multiply by p(1−p)p(1-p)p(1−p) for an effect on the probability.

Lab · what's graded

  • From a score to a probability15 pts
  • An odds ratio10 pts
  • A marginal effect15 pts
  • A log-likelihood20 pts
  • A pseudo R-squared15 pts
  • Match the vocabulary10 pts
  • Significant but useless15 pts
0/ 7 answered
Tasks
1Numeric answer15 ptsNot answered

A logit has score z=0.2z=0.2z=0.2. What is p=1/(1+e−z)p=1/(1+e^{-z})p=1/(1+e−z)? Use e−0.2=0.8187e^{-0.2}=0.8187e−0.2=0.8187 and give two decimals.

p=p =p=accepted: ± 0.005
2Numeric answer10 ptsNot answered

The slope is β=−0.054\beta=-0.054β=−0.054 per percentage point of today's return. By what factor are the odds multiplied, eβe^{\beta}eβ? Use e−0.054e^{-0.054}e−0.054 and give three decimals.

or=or =or=accepted: ± 0.003
3Numeric answer15 ptsNot answered

At a fitted probability p=0.55p=0.55p=0.55 and β=−0.054\beta=-0.054β=−0.054, what is the marginal effect p(1−p)βp(1-p)\betap(1−p)β on the probability? Give four decimals.

me=me =me=accepted: ± 0.0003
4Numeric answer20 ptsNot answered

The model gave the probability of an up day as 0.80.80.8, 0.30.30.3 and 0.60.60.6, and the outcomes were up, down, up. The probabilities of what happened are 0.80.80.8, 0.70.70.7 and 0.60.60.6. What is the log-likelihood ln⁡0.8+ln⁡0.7+ln⁡0.6\ln0.8+\ln0.7+\ln0.6ln0.8+ln0.7+ln0.6? Use ln⁡0.8=−0.2231\ln0.8=-0.2231ln0.8=−0.2231, ln⁡0.7=−0.3567\ln0.7=-0.3567ln0.7=−0.3567, ln⁡0.6=−0.5108\ln0.6=-0.5108ln0.6=−0.5108 and give two decimals.

ll=ll =ll=accepted: ± 0.01
5Numeric answer15 ptsNot answered

The intercept-only model has ℓ0=−69.3\ell_0=-69.3ℓ0​=−69.3 and your model has ℓ=−60\ell=-60ℓ=−60. What is McFadden's 1−ℓ/ℓ01-\ell/\ell_01−ℓ/ℓ0​? Give three decimals.

r2=r2 =r2=accepted: ± 0.003
6Match10 ptsNot answered

Match each term with its meaning.

Pick the partner of each item on the left.

Log-odds
Odds ratio
Marginal effect
Maximum likelihood
7Explain in words15 ptsNot answered

The lagged-return slope has p=0.019p=0.019p=0.019, yet the logit's hit rate is only 54.97%54.97\%54.97% against 54.86%54.86\%54.86% for always saying up. In one or two sentences, explain why a significant slope does not make a trading signal.

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