1/12 how to build a prediction market in 5 minutes using math from...

@probabilitygod
probability god@probabilitygod
22 views Sep 11, 2025 ~2 min read
Advertisement
1
1/12

how to build a prediction market in 5 minutes using math from a 2016 microsoft article 🧡

(github python repo link in the last tweet)
Media image
2
2/12

imagine a football match between xrays and yanks.

20 experts each receive $500 tokens and can buy shares of either outcome.
buying shares of one team pushes its probability ↑, and the other ↓.

prices eventually stabilize which allows us to infer the odds.
3
3/12

We initialize the market with 100 units of liquidity and [0,0] initial shares
the market closes before kickoff.
after the game, holders of the winning shares are paid out.

this setup is called a prediction market.
the backbone is the logarithmic market scoring rule (LMSR).
4
4/12
the LMSR math works off a cost function:

C(x,y) = b*ln( e^{x/b} + e^{y/b} )
x, y: outstanding shares of each outcome
b: liquidity parameter (higher b = smoother prices)

this cost is the market maker’s max liability.
Media image
5
5/12
a trader’s cost to buy shares is the difference in cost function before vs. after the trade:

Cost_trans = C(x+ Ξ”x, y) - C(x,y)

same logic if buying outcome y.
this is why the more you buy, the more expensive each new share gets.
Media image
6
6/12
from the cost function we extract probabilities.

P(0) = e^{x/b} / [e^{x/b} + e^{y/b}]

P(1) = e^{y/b} / [e^{x/b} + e^{y/b}]

the marginal price of a share = implied probability of that outcome.
Media image
7
7/12
quick demo:
init: liquidity = 100, outstanding = (0,0)
probs = (0.5, 0.5)

trader buys 20 shares of outcome 0 β†’ pays $10.5
new probs β‰ˆ (0.55, 0.45)

another buys 20 shares of outcome 1 β†’ pays $9.5
new probs = (0.5, 0.5) again
8
8/12
keep going:
big buy 60 shares on outcome 0 β†’ probs shift to (0.65, 0.35)
then a trader sells back 10 shares β†’ probs adjust to (0.62, 0.38)

trades continuously reshape the probability curve.
9
9/12
note: the market maker takes risk.

in one branch he might owe $70 but has only collected $48 (loss = -$22).
in another branch he owes $20 and has collected $48 (profit = +$28).

why risk this?
to extract valuable probabilistic info before the event.
10
10/12

the magic of LMSR is that with just:
liquidity parameter b
outstanding share counts

…you can run any prediction market.

no oracles, no manual odds setting. just math.
11
11/12

here's a quick python implementation where you can:
buy/sell shares
update prices + probabilities
see the market maker’s risk in real time
ONLY thing you need to initiate is the outstanding shares and liquidity.

github.com/michalisl888/p…
Actions
What You Can Do
  • Export as PDF or Markdown
  • Batch Export to Notion
  • Bookmark & Highlight
  • Screenshot Tweet
Create Free Account

Includes 7-day Premium trial

Advertisement