The Claude Quant PlaybookDownload ebookDownload ebook

Law of total probability

intermediateProbability3 of 12

Split the world into scenarios, find the chance of the event inside each one, and add them up weighted by how likely each scenario is. The result is the overall chance of the event.

Build a trading system with Claude.Download ebook

01The formula

the event you care about, here: a losing day
scenarios that do not overlap and cover every case, here: calm days and stressed days
the chance of A inside scenario i
how likely scenario i is

02See it move

03Where it is used

04Why traders use it

It is often easier to say what happens in each scenario than to say what happens overall. This formula lets you build the overall chance from simple pieces, and it is the denominator of Bayes' theorem.

05Worked example

If 20% of days are stressed, a strategy loses on 40% of calm days and 70% of stressed days. Overall it loses on 46.0% of days: 32.0% from calm days plus 14.0% from stressed ones.

06How it is built

  1. The scenarios do not overlap and together cover everything, so splits into the pieces .
  2. So .
  3. Each piece is by the multiplication rule.
  4. Substitute to get .

07The common mistake

Using scenarios that overlap or leave gaps. If a day can be both calm and stressed, or neither, the weights no longer add up to 1 and the total is wrong.

08In Python and LaTeX

p_stress = 0.20
loss_calm, loss_stress = 0.40, 0.70
p_loss = (1 - p_stress) * loss_calm + p_stress * loss_stress
print(round(p_loss, 4))  # 0.46
P(A) = \sum_i P(A \mid B_i)\,P(B_i)

09Where it fits

Rather not code the maths yourself? Describe your trading idea and let AI build the bot.

Build a bot with AgenKit

The worked example and the model run the same code, so every number matches. Models simplify markets on purpose. This is education, not financial advice.