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

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.
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).
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
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.
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.
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.
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β¦



