σμ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
  • 日本語
  • 中文
scikit-learn skill›Module 2 · The core models›Topic 2.4·~50 minIntermediate

Fitting and judging a direction classifier

Skill positionModule 2 of 4 · Topic 4 of 6
2.4 Fitting and judging a direction classifier
—Lab score— / 100Total XP—Streak—
Lecture0% read

2 min read

01

A probability, a baseline and a fair test

Logistic regression turns a linear score z=b₀+b₁x₁+…+bₚxₚ into a probability p=1/(1+e^(-z)). The score is the log of the odds: lnp/(1-p)=z, so one extra unit of xⱼ multiplies the odds of an up day by e^bⱼ. Put a StandardScaler in front, inside a Pipeline, and the unit becomes one standard deviation, which makes the odds ratios of different features comparable. The model is fitted by minimising the log loss -1/nΣ(yln p+(1-y)ln(1-p)) plus a penalty controlled by C (a small C means a strong penalty). The fitted object gives predict_proba for probabilities and predict for the class at the threshold 0.5.

A direction model must be judged against what it could achieve by doing nothing. About 55% of SPY days are up days, so always predicting 'up' is right 55% of the time: that is the baseline, and it must come from the train labels, because the test labels are not known when you predict. Accuracy depends on the threshold; the AUC does not, and equals the probability that a random up day gets a higher score than a random down day (0.5 means no skill). The log loss punishes confident mistakes. With four features known at the close, split in time (70% for training, the later 30% for testing), the lab model gets an accuracy of 55.3% against 55.1% for the baseline, an AUC of 0.501, and a log loss of 0.688, barely under the 0.690 of a coin. Odds ratios just under 1 say that yesterday's rise slightly lowers the odds of another, a real but untradable effect.

  • Judge against a baseline taken from the train labels: predicting the majority class already scores about 55%.
  • AUC and log loss do not depend on one threshold; 0.5 and 0.69 are the values of no skill.
  • Scale inside the pipeline, then e^bⱼ is the odds ratio per one standard deviation.

Lab · what's graded

6 tasks · 100 pts
  • Splitting in time10 pts
  • The pipeline10 pts
  • Three scores20 pts
  • The majority-class baseline15 pts
  • Odds ratios15 pts
  • The SPY direction study30 pts
Explorer · lab-sl-17
▾ lab-sl-17
▾ data
…
bash · in-browser
learner@quantcraft:~/lab-sl-17$
Python not loaded yetPythonLn 1, Col 1Spaces: 4UTF-8

Reset this topic?

Everything in lab-sl-17 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