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.

Proper scoring rule elicit one honest belief Sequential Market scoring rule — LMSR cost C(q)=b·log Σ e^(qᵢ/b) Pooled Parimutuel · DPM · pm-AMM self-funding, endogenous odds Convex conjugate Constant-function AMM x·y=k (Uniswap), Balancer Continuous order flow → CDA · Frequent Batch Auction price-time priority vs. uniform-price discrete clearing

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_rules

Parimutuel markets

Pool betting with endogenous odds; Pennock's dynamic parimutuel market.

parimutuel

LMSR

Hanson's logarithmic market scoring rule; bounded worst-case loss.

lmsr

Cost-function market makers

The general convex-potential maker; LMSR is its entropic special case.

cmm

Automated market makers

Constant-product / constant-mean CFMMs and impermanent loss.

amm

pm-AMM

Paradigm's parimutuel AMM for binary markets via Gaussian score dynamics.

pm_amm

Continuous double auction

Price-time-priority limit order book; the engine of modern exchanges.

cda

Frequent batch auction

Uniform-price batch clearing that neutralises the latency race.

fba

Perpetual futures

The funding-rate tether, mark price, and liquidation.

perp

Perpetual demand lending pools

GMX/Jupiter/Hyperliquid pools: arbitrage, target weights, delta hedging.

pdlp

Peer prediction

Eliciting truth without ground truth — Bayesian Truth Serum.

peer_prediction

Forecast aggregation

Linear, logarithmic, and depth-trimmed opinion pools.

aggregation

Try 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.