Mechanisms
Reference implementations of the rules by which markets elicit, aggregate, and reward predictions — and the literature behind them.
A market mechanism is a set of rules that turns scattered private beliefs
into a price, a probability, or a payout. This repository collects small,
readable, numpy-only reference implementations of the major
ones — proper scoring rules, parimutuels, market scoring rules, automated
market makers, perpetual futures, order books, batch auctions, peer
prediction, and forecast aggregation — each paired with the academic work
that explains it.
The organising idea is a duality between proper scoring rules and market mechanisms. A proper scoring rule elicits one honest belief. Run it sequentially and it becomes a prediction-market maker (Hanson's LMSR). Run it as a pool and it becomes a parimutuel. Take its convex conjugate and you have a DeFi constant-function market maker. The same mathematics, wearing different institutional clothes.
One root, many institutions. See the catalog for each mechanism and its formula.
The catalog
Proper scoring rules
Log, Brier, spherical; pinball & interval scores; CRPS and the multivariate energy score.
scoring_rulesParimutuel markets
Pool betting with endogenous odds; Pennock's dynamic parimutuel market.
parimutuelLMSR
Hanson's logarithmic market scoring rule; bounded worst-case loss.
lmsrCost-function market makers
The general convex-potential maker; LMSR is its entropic special case.
cmmAutomated market makers
Constant-product / constant-mean CFMMs and impermanent loss.
ammpm-AMM
Paradigm's parimutuel AMM for binary markets via Gaussian score dynamics.
pm_ammContinuous double auction
Price-time-priority limit order book; the engine of modern exchanges.
cdaFrequent batch auction
Uniform-price batch clearing that neutralises the latency race.
fbaPerpetual futures
The funding-rate tether, mark price, and liquidation.
perpPerpetual demand lending pools
GMX/Jupiter/Hyperliquid pools: arbitrage, target weights, delta hedging.
pdlpPeer prediction
Eliciting truth without ground truth — Bayesian Truth Serum.
peer_predictionForecast aggregation
Linear, logarithmic, and depth-trimmed opinion pools.
aggregationTry them
The interactive demos run the JavaScript ports of these mechanisms directly in your browser — and that same JavaScript is checked for numerical parity against the Python reference implementations in the test suite, so the demos can't drift from the library.
Research
The repository's research notes survey the literature behind each mechanism, cross-linked to the code and to a consolidated bibliography. The conceptual backbone is the survey Novel Statistical and Market-Inspired Mechanisms for the Elicitation, Aggregation, and Rewarding of Predictive Contributions (PDF), which traces the arc from strictly proper scoring rules through AMMs, DPMs, the pm-AMM, frequent batch auctions, and peer prediction to the microprediction paradigm of web-scale autonomous prediction networks.
Install
git clone https://github.com/microprediction/mechanisms
cd mechanisms
pip install -e ".[test]"
python examples/quickstart.py
pytest -q
Selected references
The full, grouped list is on the bibliography page.
- Gneiting, T. & Raftery, A. E. (2007). “Strictly Proper Scoring Rules, Prediction, and Estimation.” JASA 102(477).
- Hanson, R. (2007). “Logarithmic Market Scoring Rules for Modular Combinatorial Information Aggregation.” J. Prediction Markets 1(1).
- Pennock, D. (2004). “A Dynamic Pari-Mutuel Market for Hedging, Wagering, and Information Aggregation.” ACM EC.
- Angeris, G. et al. (2021). “An Analysis of Uniswap Markets.” Cryptoeconomic Systems.
- Moallemi, C. & Robinson, D. (2024). “pm-AMM: A Uniform AMM for Prediction Markets.” Paradigm.
- Budish, E., Cramton, P. & Shim, J. (2015). “The High-Frequency Trading Arms Race.” QJE 130(4).
- Prelec, D. (2004). “A Bayesian Truth Serum for Subjective Data.” Science 306.
- Cotton, P. (2022). Microprediction: Building an Open AI Network. MIT Press.