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".
Count within the conditioning event
- Out of N equally weighted observations, let nB satisfy B and nAB satisfy both A and B. Then .
- Divide numerator and denominator by N to obtain . This requires P(B)>0.
Out of 100 days, a signal fires on 20 and wins on 12 of those: conditional win rate=12/20=60%.
is a different number from , 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
Derive Bayes from the joint probability
- The same joint event has probability . Divide by P(E).
- Partition E into H and not-H: add and .
Base win probability .5; signal likelihoods .6 on wins and .3 on losses. Posterior=.30/(.30+.15)=2/3.
is your hypothesis ("this trade wins"), is the evidence you just observed (a volume spike, an earnings beat, a regime flag). The prior is your base rate. The likelihood ratio 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 . The signal fires in 60% of winners and 30% of losers. , as a percentage?
. 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- Start with counts, probabilities and averages
- Random outcomes, sample averages and the limits of the bell curve
- Conditional probability: update a belief with evidence
- Prediction markets: probability, price and net expected value
- Expected value: measure the payoff before choosing the risk
- Correlation: how many strategies do you really have?
- Conditional probability and Bayes: where the edge actually lives
- The central limit theorem: sampling means under explicit assumptions
- Estimation uncertainty and Bayesian updating
Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations