This post is mostly a copy of David Pennocks article, which seems be offline now. It can still be read via Google Cache. Since I followed this for my prediction market implementation, I want to preserve the information.
Imagine a joint-market, where you can buy yes and no shares for a certain prediction. If the prediction turns out true, each yes share is worth 1€, while no shares are worthless. If the prediction turns out false, yes shares are worth 0€, but no shares yield 1€. Naturally, the price for a share until resolution will be between 0€ and 1€.
Our prediction market will have few traders. Thus, we want an automatic market maker, who acts as a partner to every trade. This way nobody has to wait for his orders to be filled. We use the logarithmic market scoring rule (LMSR) market maker by Robin Hanson. This market maker adapts the price after each trade. Here is the formula for buying a single share:
C = b ⨉ ln(ey/b+en/b)
For computing the value you need the number of yes shares sold so far y, the number of no shares sold so far n, and the parameter b. As usual ln is natural logarithm function and e is 2.718….
If you want to buy multiple shares, the price is the difference between the costs. For example, no shares have been sold so far and we want to buy 10 yes shares (and b=100):
C(10,0)-C(0,0) = 100 ⨉ ln(e10/100+e0) - 100 ⨉ ln(e0+e0) = $5.12
The parameter b describes kind of the depth of the market. The lower it is, the bigger the price changes when you buy shares.
When the market is closed and the prediction is to be settled. Somebody has to balance the market, which means to buy yes or no shares such that y=n. No the total money invested into the market is just enough for payout. Usually, the creator of the market is responsible for balancing this. The clever part is that the cost of balancing is bounded. For example, with b=100, it is always lower than 69.31€.
max_cost = b ⨉ ln(2)
If the market is wrong (for example, <50% when prediction was true), the you even get up to 69.31€ out during settlement.
Since we have a prediction market, we also want to know the current price (aka chance):
price = ey/b/(ey/b+ex/b)
That is enough math to implement a prediction market for binary futures.