Project at a glance

RoleDesign, methodology and engineering, solo
ScopeFour processes around one database; 47 tables; a 20-page dashboard; 801 tests in 51 files; 86 commits
StackPython 3.13, FastAPI, PostgreSQL 17 in Docker, React 19, TypeScript, Vite, Tailwind
StatusRuns on one machine and trades on paper only. The code for real orders is written and switched off. The screens show the system's own paper record against public market data, and every dollar figure in them is paper money.

Why I built it

A language model will give a probability for anything, and it is hard to tell whether those probabilities are any good. A prediction market is a hard benchmark for them: a price with real money behind it, and a result that arrives on a known date. I built pmkt to ask one question and answer it honestly: was the forecaster closer to what happened than the market's own price was?

The scorecard at the top of this page is the answer so far. Of fifteen forecasters, one is ahead of the market, seven are level with it, three are behind, and four have too few results to say.

What it does

Records the market as it moves

A recorder follows public markets on Kalshi, a US prediction-market exchange, and stores each market's price and its full order book. Everything else is measured against that record, so a forecast is always compared with the price that stood at the moment it was made.

One public market as the recorder stored it: the bid, the ask, and the order book at each price.

Makes each agent commit before it sees the price

An agent reads the market's rules, searches the news and reads its sources. It must then write down its own estimate before the tool that shows the price will answer. After that it may revise. Both numbers are bet on paper, separately, which shows what seeing the price was worth.

The same forecasts bet two ways on paper: the final forecast, and the first estimate made before the agent saw the price. All dollar figures are paper money.

Follows every forecast to its result

Each forecast stays on the record beside the price it was made against, through the game and on to the result. A page for each game puts the price, the forecasts and the changes of score on one chart.

One game from the paper record: the market's price for a Chicago win, each forecast as a dot, and each change of score as a dashed line.

How it is built

The rest of this page is for the engineer who wants the detail.

Architecture

pmkt is four long-running Python processes and one database. The recorder stores the market. The agents process runs the forecasters. The engine turns forecasts into paper bets. The API serves the dashboard. They never call each other: each reads and writes tables, so any one can stop or restart without the others noticing.

Architecture: a recorder, an agents process, an engine and an API, each with its own outside connection, sharing one PostgreSQL database and making no direct calls to each other.

One forecast, from market to scorecard:

  1. The recorder follows the markets in the sectors that are switched on, out of 33. It listens to the exchange's public stream and polls as well, so a dropped stream loses nothing. Older order books are thinned to one per market every five minutes, and later to one an hour.
  2. The agents process picks a market and runs an agent on it. The agent works through seven tools and ends by submitting a probability with its sources.
  3. The engine reads the new forecast, runs its risk checks and, if they pass, fills a paper bet against the recorded order book.
  4. When the market settles, the forecast and the price it was made against are scored on the result.
  5. The API serves the pages and pushes changes to the browser over a server-sent event stream.

One database, a login for each process

PostgreSQL 17 runs in one Docker container, published only on the local machine, with its data in a named volume and its memory settings raised for a recorder that writes order books in bulk.

Each process signs in with its own database login, and each login may write only what its job needs:

  • The recorder may write market data and nothing else.
  • The agents process may add runs, steps, documents and forecasts. It cannot change a forecast once written.
  • The engine may write portfolios, decisions, positions and fills. It may raise a halt. It cannot alter a forecast or clear a halt.
  • The API may write agent definitions, settings and the owner's decisions. It cannot write an order, a position or a forecast.

A separate owner login changes the schema. The integration tests sign in with these logins, try writes they are not allowed, and expect the database to refuse.

How an agent forecasts

The seven tools are: read the market and its rules without the price, search the news, fetch a public page, read the agent's own earlier forecasts, record a first estimate, read the price, and submit.

  • The price is locked. The price tool refuses until a first estimate is recorded. This is enforced in code, where a prompt cannot talk its way past it.
  • Sources are counted. A forecast that rests on fewer than two pages the agent actually read is stored and never traded.
  • Pages are data. Fetched text is wrapped and marked as page content, not instructions, and only public addresses are fetched.
  • Engines are swappable. OpenRouter, Claude Code and Codex all drive the same tool set, so a result belongs to the model and not to its harness.

Some forecasters use no language model at all, among them a normal-margin model for football and a point-by-point model for tennis. They are a baseline for the agents.

Paper bets that do not flatter

A paper bet is easy to make look better than a real one, so the engine works against that.

  • Fills walk the book. A bet is filled against the recorded order book, best price first, with the exchange's fee worked out per fill and rounded up.
  • In-play bets wait. During a game a bet is filled at the prices standing at least 8 seconds after the forecast was made, never the ones at that instant, and a forecast is dropped once it is 90 seconds old. A paper bet cannot take a price that had already gone.
  • Every decision shows its checks. Twelve named risk checks run on each idea, and their results are stored with it in plain words, pass or fail.
  • Refusals are followed too. A bet the checks refused is still tracked to its result, so the checks themselves can be judged.

Scoring

Each settled forecast gets a Brier score, and so does the market's mid price at the moment the forecast was made. The difference is the forecaster's edge. Forecasts on one game move together, so the 90% range comes from 2,000 resamples of whole games, not of single forecasts. A forecaster is called ahead only when its whole range is above the market's line, and one with under ten games or events gets no verdict.

On the 3,134 forecasts decided so far, the market's price scored 0.215, the final forecasts 0.216 and the first estimates 0.224, where lower is better. The agents are level with the market, and seeing the price helps them.

Real orders: written, switched off

The path to real orders exists and is off. Its design is the careful part: an order is saved before it is sent, sent once and never re-sent, and checked against the exchange afterwards, with a halt on any mismatch. A kill switch stops everything, and a gate keeps the path shut until the paper record has earned it.

Testing

LayerTest filesWhat it covers
Unit33Pricing, fees, risk checks, scoring, the forecasting models, the agent tools
Integration18A real PostgreSQL: the role permissions, the recorder's store, the engine, the API

That is 801 tests, three of them property tests that generate their own cases. Types are checked in strict mode. Everything runs locally; there is no hosted CI.

Limits and what is next

This is paper trading, and a short paper record says very little either way. A paper fill cannot know its place in the queue. The football model is simple. The system runs on one machine for one user.

What the project demonstrates

pmkt shows how I test a claim about AI: choose a benchmark that cannot be flattered, measure before trusting, and put the safety rules where no prompt can reach them.