Trading Dev AcademyFree quant education

Free lesson · Financial machine learning

Logistic classification and cost-aware entry thresholds

Open interactive lessonPractice calculationsExplore labs

Start with the idea

A classifier estimates the probability of a defined outcome. Trading needs both that probability and the size of gains, losses and costs. Classification accuracy alone cannot determine the best action.

Symbols, units & horizon
  • x: current feature vector
  • β,b: fitted coefficients and intercept
  • z: dimensionless logit
  • p: predicted positive-outcome probability
  • y: observed label 0 or 1
  • L: single-observation log loss
  • ln: natural logarithm
  • ∂L/∂z: gradient used in fitting
  • Probabilities: assume a calibrated target distribution for decisions

When and why to use this

Use calibrated classification for entry filtering, convergence events and fill outcomes when the decision’s payoff structure is explicit.

For a binary target, logistic regression converts a linear score into a number between zero and one. Train by minimising log loss, optionally with regularisation. Class weights and oversampling change the effective training distribution and may require recalibration before interpreting the output as a probability.

Define the positive outcome precisely: positive gross return, positive net return or reaching a take-profit before a stop are different labels. Avoid charging the same cost twice when both the target and decision rule already include it. Time-based labels need the same hold/exit convention used in the backtest.

Use conditional payoff estimates where possible: a high probability of a tiny gain may be worse than a lower probability of a large gain. Probability calibration and uncertainty near the decision threshold matter more than maximising the count of correct signs.

p=11+e−z,z=β𝖳x+b,L=−yln⁡p−(1−y)ln⁡(1−p),∂L∂z=p−y
Model assumptions, derivation and arithmetic

Logistic classification and cost-aware entry thresholds

  1. The logistic derivative is dp/dz=p(1−p), obtained by differentiating the reciprocal exponential expression.
  2. Differentiate loss with respect to p: −y/p+(1−y)/(1−p). Multiply by dp/dz and simplify to p−y.
  3. For payoffs G,L_loss and cost C, act only if pG−(1−p)L_loss−C is positive under the model, with risk and uncertainty constraints still applied.
Work it by hand

At logit 0, p=.5. For y=1, log loss=ln2≈.6931 and logit gradient=−.5. If gains and losses are each 10 bps and costs are 2 bps, break-even probability is .6, not .5.

Apply it in a strategy

  • Define the outcome and fit a regularised baseline on chronological training data.
  • Calibrate using disjoint past validation predictions, then choose a payoff-aware threshold within the inner loop.
  • Evaluate resulting trades, including rejected opportunities, at the same risk and execution assumptions as the baseline.

Research deliverable

Provide a reliability plot and a threshold-versus-net-value table rather than only accuracy or AUC.

Python implementation

Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.

from math import exp,log

def logistic(z):
    if z>=0: return 1/(1+exp(-z))
    e=exp(z); return e/(1+e)

def binary_loss_gradient(z,label):
    if label not in (0,1): raise ValueError("Binary label required")
    p=logistic(z)
    loss=max(z,0)-z*label+log(1+exp(-abs(z)))
    return p,loss,p-label

print(binary_loss_gradient(0,1))

Continue learning

Machine Learning for Quantitative Strategy Development — all lessons
  1. Choose the model’s job: targets, horizons and decision layers
  2. Feature engineering, missingness and training-only transformations
  3. Regularised regression: an interpretable alpha baseline
  4. Logistic classification and cost-aware entry thresholds
  5. Trees and boosting: nonlinear interactions with controlled complexity
  6. Calibration, meta-labels and conditional payoff estimation
  7. Unsupervised learning, clusters and latent risk structure
  8. From model forecasts to a constrained strategy

Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations