Logistic regression
A model for yes-or-no outcomes. It fits a straight line to the log-odds and turns it into a probability with the S-shaped sigmoid.
01The formula
- the probability of the event (say, tomorrow is an up day) given the signal x
- the sigmoid: squashes any number into a probability between 0 and 1
- the intercept: shifts the curve left or right
- the slope: how sharply the probability changes with x
- the log-odds, ln(p/(1−p))
02See it move
03Where it is used
- Quant researcherPredicts the direction of the next move, or whether an order will be filled, from a handful of signals.
- Execution traderEstimates the chance a passive order fills before the price moves away, to choose between waiting and crossing the spread.
- Risk managerScores the probability of default or of a margin call from account features.
04Why traders use it
A probability is more useful than a yes or no: you can size a trade by it and check it is calibrated. Logistic regression is the simplest model that gives one, and its coefficients read directly as changes in log-odds.
05Worked example
With β₀ = −0.50, β₁ = 1.50 and today's signal at 1.0, the log-odds are 1.000, the odds 2.718 and the probability of an up day 73.1%. The model calls up for any signal above 0.333.
06How it is built
- A probability lives in but a line does not, so model the log-odds instead: .
- Solve for : .
- Fit by maximum likelihood: maximise , usually by gradient steps.
- The 50% boundary is where the log-odds are zero: .
07The common mistake
Reading β₁ as a change in probability. It is a change in log-odds; the effect on the probability is largest near 50% and tiny out in the flat tails of the S.
08In Python and LaTeX
from scipy.special import expit b0, b1, x = -0.5, 1.5, 1.0 print(round(expit(b0 + b1 * x), 4)) # P(up | x)
P(y = 1 \mid x) = \sigma(\beta_0 + \beta_1 x) = \frac{1}{1 + e^{-(\beta_0 + \beta_1 x)}}09Where it fits
Rather not code the maths yourself? Describe your trading idea and let AI build the bot.
Build a bot with AgenKitThe worked example and the model run the same code, so every number matches. Models simplify markets on purpose. This is education, not financial advice.