Skip to main content

pretium

determinism licence: MIT OR Apache-2.0 python 3.11+

A market simulator you can run a strategy against. Rust core, Python API.

Give it a seed and a set of companies and it runs a market forward: prices, a limit order book, fills, and an economy that advances itself daily. Your orders match against real depth, so trading moves the price the way it would anywhere else.

It exists because historical data can't answer two questions. What would have happened if I'd traded differently, and what actually caused this price move.

Install

pip install pretium

The API may still move before 1.0. What will not move is a published result: anything that changes the simulated trajectory arrives as a new model preset rather than an edit to an existing one, so a run you cited last month reproduces this month.

In thirty seconds

import pretium as pt

universe = pt.Universe.random(40, seed=111)

spec = pt.StrategySpec.momentum(lookback_days=1.0, top_k=5)
scores = pt.evaluate({"mine": spec}, seed=7, universe=universe, days=10)

scores["mine"].return_pct            # what it made
scores["mine"].impact_bps            # what its own footprint cost
scores["mine"].strategy_fingerprint  # sha256, cite this

That's one market draw, which tells you as much about the seed as about the strategy. pt.rank runs many seeds and compares them with a paired sign test.

What makes it different

Determinism that's checked. The crate ships its own exp, log, sin and cos instead of calling the platform libm. Every release builds five targets, runs one fixed simulation inside each, and compares digests. A disagreement fails the release. A WebAssembly build produces the same digest as the native one.

Ground truth you can read. The simulator computed every price, so it can tell you why. One row per instrument per tick, with seven factor contributions that sum to the move and a residual around 1e-16. No historical dataset carries those labels. You can see that a stock fell, never that 60% of the fall was order-flow pressure.

Counterfactuals you can run. The same seed runs with and without your orders, so every fill is priced against the market where you never traded. That's the number TCA vendors approximate.

Results someone else can check. A StrategySpec is a declarative, hashable document rather than an arbitrary callable. A RunManifest carries the seed, universe, macro conditions, scenario, model and strategy together with the expected digest. reproduce() refuses on a mismatch and names the culprit, because a manifest that quietly reproduced a different market would be worse than no manifest.

Driving it from an agent

pip install "pretium[mcp]"
claude mcp add pretium -- pretium-mcp

Eleven read-only tools over the simulator, so a coding agent can ask whether a momentum strategy beats buy-and-hold here, and whether the difference is real. Strategies, universes and scenarios are composed as data. There's no path from a tool argument to code execution.

Every result carries computed caveats and full provenance. A model summarising a result has the tool output and nothing else, and will otherwise report return_pct: 88.7 as "the strategy made 88.7%". The MCP server has the tool list and the client configuration.

What it's bad at

Good results here don't predict real returns. The price process comes from a known model, so a strategy that fits that model's structure will look excellent and teach you nothing. A strategy that fails here is more informative, because it broke against a live order book under honest impact costs.

Realism is a stated envelope, not a score. pt.facts.measure() reports ten statistics against real-market bands. At 252 days the shipped pt-v3 preset holds nine of the ten in band, and holds the same nine on axes the calibration never saw: fresh seeds, and a fresh 60-name universe.

The tenth is the autocorrelation of volume changes, which misses by 13.7 seed-standard-deviations. It's excluded from the calibration objective deliberately, because an optimiser pointed at an unreachable target doesn't fail cleanly, it distorts every other parameter chasing it. In practice a volume forecast here is never wrong twice running, so an execution algorithm faces an easier scheduling problem than the one it was written for.

Six gaps are measured and named rather than assumed. The certified horizon is 252 days and the model doesn't hold beyond it. Volatility memory decays exponentially where real markets decay hyperbolically. Tails are too thin over multi-year windows. Scenario response is directionally right but not calibrated in magnitude. And certification was measured on a sector-balanced roster, which no real index is. The realism envelope states each gap and what it forbids. pt.envelope.check() refuses to certify a question that falls outside one.

Single venue, no latency, no strategic counterparties. Orders arrive instantly, there's one book per name, and you trade against a market maker and aggregate flow rather than agents that adapt to you.

Worked examples

Six notebooks and two scripts in examples/, numbered in reading order and executed as part of the test suite:

what it covers
01-first-simulation Universe, engine, order book, determinism
02-evaluating-a-strategy Specs, baselines, ranking across seeds
03-why-did-the-price-move The seven factors that sum to every move
04-how-realistic-is-this The realism panel and the gaps
05-training-an-agent The Gymnasium environment, and what size costs
06-execution-and-impact TCA and the counterfactual run
09-a-pandemic-shaped-market A real 2020-21 macro path, and which fields actually transmit

Or a whole study in one file. Sweep, evaluation, TCA and replay in about five seconds:

python examples/07-research-workflow.py

Documentation

Full docs: simoncoombes.github.io/pretium

Getting started and core concepts. Agents, evaluation and the RL environment. Scenarios and macro paths, strategy specs, model presets, checkpointing and forking, sharing a run, Arrow output and streaming sweeps, SEC EDGAR loading, transaction cost analysis, the MCP server, running in the browser, the realism envelope and metrics, and the conventions worth reading before you hit them.

Contributing

See CONTRIBUTING.md, and RELEASING.md for how a version reaches PyPI and crates.io. One rule shapes the rest: a change to the simulated trajectory is a breaking change, whatever its size. A market that runs differently from the same seed invalidates every published result that cited it.

Citing this

See CITATION.cff, or cite a specific result by its manifest. The seed, the universe fingerprint, the model fingerprint and the strategy fingerprint together identify exactly what ran.

Licence

MIT OR Apache-2.0, at your option. See LICENSE-MIT and LICENSE-APACHE.

Metadata

Release files for pretium 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pretium 0.1.3
File Size Uploaded
pretium-0.1.3.tar.gz 478.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pretium 0.1.3
File
pretium-0.1.3-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details
pretium-0.1.3-cp311-abi3-manylinux_2_34_x86_64.whl CPython 3.11 abi3 Linux glibc 2.34+ x86-64 Details
pretium-0.1.3-cp311-abi3-manylinux_2_34_aarch64.whl CPython 3.11 abi3 Linux glibc 2.34+ ARM64 Details
pretium-0.1.3-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details
pretium-0.1.3-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details

Total release size: 4.3 MB

Release files / pretium-0.1.3.tar.gz

Download URL pretium-0.1.3.tar.gz
Size 478.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f45b5451f1b03aded401268d180ba83d14491eae492fe9c2e801454eebeec16e
BLAKE2b-256 checksum
How to use checksums
db01dc942c00b9ab042ac5a0f0c22bb37be94abbd54b7fa0223021a749f20ad8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.

Transparency log

Release files / pretium-0.1.3-cp311-abi3-win_amd64.whl

Download URL pretium-0.1.3-cp311-abi3-win_amd64.whl
Size 693.3 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
296ec006aa5eb121a28f409b3758ef105a64e3872656f6b5b1afae8850928185
BLAKE2b-256 checksum
How to use checksums
c7c1146a6e8cd32bfbe08fa6b55b421f6fc51e334af6710d0144258317b9f7bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.

Transparency log

Release files / pretium-0.1.3-cp311-abi3-manylinux_2_34_x86_64.whl

Download URL pretium-0.1.3-cp311-abi3-manylinux_2_34_x86_64.whl
Size 795.2 kB
Tags CPython 3.11 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
3669832b0da651504a4d90a08aa993244ddabcda51287896c7643b876cb55ae9
BLAKE2b-256 checksum
How to use checksums
9a7f271305a5ab420f10bc9b035ac2dd33a3f9b2e440deb23af951faa61c6a52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.

Transparency log

Release files / pretium-0.1.3-cp311-abi3-manylinux_2_34_aarch64.whl

Download URL pretium-0.1.3-cp311-abi3-manylinux_2_34_aarch64.whl
Size 779.4 kB
Tags CPython 3.11 Linux glibc 2.34+ ARM64 abi3
SHA-256 checksum
How to use checksums
56556cc0de31a5bcda4be05f4a51a60168b8aa17b2e29148e502887a3522539b
BLAKE2b-256 checksum
How to use checksums
8b805480d37809c8a8d2d93e47d829fcebb4c619017623b4ce4c66da95a2aee3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.

Transparency log

Release files / pretium-0.1.3-cp311-abi3-macosx_11_0_arm64.whl

Download URL pretium-0.1.3-cp311-abi3-macosx_11_0_arm64.whl
Size 747.8 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
36a452c829be2c1284192ab3c6c94567e61e7d548af1291097a563791550d613
BLAKE2b-256 checksum
How to use checksums
17c87022ec7a5e77355272d06d5fead1042d1d8c26d5a47638f5601271fbb0fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.

Transparency log

Release files / pretium-0.1.3-cp311-abi3-macosx_10_12_x86_64.whl

Download URL pretium-0.1.3-cp311-abi3-macosx_10_12_x86_64.whl
Size 768.3 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
c58a724db377b3f88f6869805e97b1df32e2d89c2784c22b24497609574543c8
BLAKE2b-256 checksum
How to use checksums
81a823e5d449aff36661c317431898a36671f2328559259cab4699be1ec378b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.

Transparency log

Release history Release notifications | RSS feed

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.3

6 release files

0.4.2

6 release files

0.4.1

6 release files

0.4.0

6 release files

0.3.0

6 release files

0.2.0

6 release files

0.1.4

6 release files

This release

0.1.3 This release

6 release files

0.1.2

6 release files

0.1.1

6 release files

0.1.0

5 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page