Trading Dev AcademyFree quant education

Free lesson · Statistics

Conditional probability and Bayes: where the edge actually lives

Open interactive lessonPractice calculationsExplore labs

Start with the idea

Conditioning changes the group you are counting. The denominator must describe the same selected population as the numerator. Bayes’ rule reverses the direction of a conditional probability by bringing the base rate back into the calculation.

Symbols, units & horizon
  • A, B: events
  • H: hypothesis, such as a winning trade
  • E: observed evidence, such as a signal
  • P: probability
  • |: given
  • ∩: both events occur
  • ¬H: H does not occur
  • N: total observations
  • nB, nAB: counts satisfying B, or both A and B
  • P(H): prior base rate
  • P(H|E): posterior probability after evidence
  • Odds: p/(1−p), a ratio rather than a probability
  • Likelihood ratio: P(E|H)/P(E|not H)

When and why to use this

Use conditional probabilities when comparing regimes or interpreting a signal’s hit rate. Base rates matter when rare events generate many false alarms.

An unconditional win rate is an average over every market state. Conditioning can reveal differences hidden by an average: the setup works 70% of the time in one regime and 40% in another, and the trader sees 55% and calls it "decent".

P(A|B)=P(A∩B)P(B)
Algebra and arithmetic

Count within the conditioning event

  1. Out of N equally weighted observations, let nB satisfy B and nAB satisfy both A and B. Then P(A|B)=nABnB.
  2. Divide numerator and denominator by N to obtain P(A∩B)P(B). This requires P(B)>0.
Work it by hand

Out of 100 days, a signal fires on 20 and wins on 12 of those: conditional win rate=12/20=60%.

P(win|VIX<15) is a different number from P(win), and the difference is the edge upgrade. The mechanics of finding it are just counting: among all trades taken when VIX was below 15, what fraction won?

Bayes' theorem: updating instead of believing

P(H|E)=P(E|H)P(H)P(E),P(E)=P(E|H)P(H)+P(E|¬H)P(¬H)
Algebra and arithmetic

Derive Bayes from the joint probability

  1. The same joint event has probability P(H∩E)=P(E|H)P(H)=P(H|E)P(E). Divide by P(E).
  2. Partition E into H and not-H: add P(E|H)P(H) and P(E|¬H)P(¬H).
Work it by hand

Base win probability .5; signal likelihoods .6 on wins and .3 on losses. Posterior=.30/(.30+.15)=2/3.

H is your hypothesis ("this trade wins"), E is the evidence you just observed (a volume spike, an earnings beat, a regime flag). The prior P(H) is your base rate. The likelihood ratio P(E|H)P(E|¬H) is how diagnostic the evidence is. Evidence that shows up equally often in winners and losers has a ratio of 1 and changes nothing — most indicators are like this.

Base rate P(win)=0.5. The signal fires in 60% of winners and 30% of losers. P(win|signal), as a percentage?

0.6×0.50.6×0.5+0.3×0.5=0.300.45=0.667. The likelihood ratio is 2, so the odds double: 1:1 becomes 2:1.

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.

def conditional_count(both, selected):
    if not 0 <= both <= selected or selected == 0:
        raise ValueError("Require 0 <= both <= selected, selected > 0")
    return both/selected

def bayes(prior, evidence_if_h, evidence_if_not_h):
    if not all(0 <= p <= 1 for p in [prior, evidence_if_h, evidence_if_not_h]):
        raise ValueError("Probabilities must be in [0, 1]")
    joint = prior*evidence_if_h
    evidence = joint+(1-prior)*evidence_if_not_h
    if evidence == 0:
        raise ValueError("Evidence has zero probability")
    return joint/evidence

print(conditional_count(12, 20), bayes(.5, .6, .3))
def posterior_odds(prior_probability, likelihood_ratio):
    if not 0 <= prior_probability < 1 or likelihood_ratio < 0:
        raise ValueError("Invalid prior or likelihood ratio")
    odds = prior_probability/(1-prior_probability)*likelihood_ratio
    return odds, odds/(1+odds)

Continue learning

Statistics & Probability — all lessons
  1. Start with counts, probabilities and averages
  2. Random outcomes, sample averages and the limits of the bell curve
  3. Conditional probability: update a belief with evidence
  4. Prediction markets: probability, price and net expected value
  5. Expected value: measure the payoff before choosing the risk
  6. Correlation: how many strategies do you really have?
  7. Conditional probability and Bayes: where the edge actually lives
  8. The central limit theorem: sampling means under explicit assumptions
  9. Estimation uncertainty and Bayesian updating

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