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 truthful 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 truthful 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

Local scoring rules

The Hyvärinen score and m-local rules: proper scoring without the normalising constant.

local_scoring

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

Combinatorial markets

LMSR over a joint outcome space; coherent prices for conditional and combined events.

combinatorial

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

Hybrid CLOB + AMM

Match against a resting limit-order book first, route the remainder to an AMM backstop.

hybrid_market

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

Decision markets

Action-conditional markets read as ensembling; argmax, softmax, and epsilon-greedy selection.

decision_market

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.

For fun

Which countries actually invented all this? Settle it (unscientifically) with a World Cup of prediction markets, a whimsical league table of national contributions, from Julius's totalisator to Uniswap.

Research

The repository's research notes survey the literature behind each mechanism, cross-linked to the code and to a consolidated bibliography. Together they trace 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.