Skip to main content

Backtester for IMC Prosperity 4 algorithms

Project description

IMC Prosperity 4 Backtester

Build Status

Backtester for IMC Prosperity 4 algorithms.

Installation

pip install imc_p4_bt

Usage

# Backtest on all days from round 1
$ imc-p4-bt example/starter.py 1

# Backtest on round 1 day 0
$ imc-p4-bt example/starter.py 1-0

# Backtest on round 1 day -1 and round 1 day 0
$ imc-p4-bt example/starter.py 1--1 1-0

# Backtest on all days from rounds 1 and 2
$ imc-p4-bt example/starter.py 1 2

# Merge profit and loss across days
$ imc-p4-bt example/starter.py 1 --merge-pnl

# Automatically open the result in the visualizer when done
$ imc-p4-bt example/starter.py 1 --vis

# Write algorithm output to custom file
$ imc-p4-bt example/starter.py 1 --out example.log

# Skip saving the output log to a file
$ imc-p4-bt example/starter.py 1 --no-out

# Backtest on custom data
$ imc-p4-bt example/starter.py 1 --data prosperity4bt/resources

# Print trader's output to stdout while running
$ imc-p4-bt example/starter.py 1 --print

Order Matching

Orders placed by Trader.run at a given timestamp are matched against the order depths and market trades of that timestamp's state. Order depths take priority — if an order can be filled completely using volume in the relevant order depth, market trades are not considered. If not, the backtester matches your order against the timestamp's market trades.

Market trades are matched at the price of your orders, e.g. if you place a sell order for €9 and there is a market trade for €10, the sell order is matched at €9.

Matching behavior is configurable via --match-trades:

  • --match-trades all (default): match market trades with prices equal to or worse than your quotes.
  • --match-trades worse: match market trades with prices strictly worse than your quotes.
  • --match-trades none: do not match market trades against orders.

Limits are enforced before orders are matched. If your position would exceed the limit assuming all orders fill, all orders for that product are canceled.

Position Limits

Known Prosperity 4 products are defined in prosperity4bt/data.py (LIMITS).

Round Product Limit
0 EMERALDS 80
0 TOMATOES 80
1 ASH_COATED_OSMIUM 80
1 INTARIAN_PEPPER_ROOT 80

Any unlisted product defaults to 50. Override limits without editing code:

imc-p4-bt sample.py 0 --limit EMERALDS:80 --limit TOMATOES:80

Data Files

Data files are bundled for rounds 0, 1, and 2. More will be added as rounds are released.

Conversions are not supported.

Environment Variables

During backtests, two environment variables are set:

  • PROSPERITY4BT_ROUND — the round number
  • PROSPERITY4BT_DAY — the day number

These do not exist in the official submission environment — do not rely on them in submitted code.

Development

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Clone and set up
git clone https://github.com/rkothari3/IMC_P4_Backtester
cd IMC_P4_Backtester
uv venv && source .venv/bin/activate
uv sync

Changes are automatically reflected the next time you run imc-p4-bt inside the venv.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

imc_p4_bt-1.0.2.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

imc_p4_bt-1.0.2-py3-none-any.whl (1.8 MB view details)

Uploaded Python 3

File details

Details for the file imc_p4_bt-1.0.2.tar.gz.

File metadata

  • Download URL: imc_p4_bt-1.0.2.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for imc_p4_bt-1.0.2.tar.gz
Algorithm Hash digest
SHA256 8e7100142381729b26fbd5377e196bff166250dd19049c8d63189dc0b8708c24
MD5 1fc017a73548bf99994a7dbc94570833
BLAKE2b-256 152bac4d8f4df7de5f95246d33f59d312ce0b6e5257fe1b2047e2b13b4e3ee5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for imc_p4_bt-1.0.2.tar.gz:

Publisher: build.yml on rkothari3/IMC_P4_Backtester

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file imc_p4_bt-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: imc_p4_bt-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for imc_p4_bt-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9e2b7a57ebbfb06c4636a3c7c405bf016496cf4ea4c7a70a7e154eb9316b9ccf
MD5 8d7bfc9759c70bde798782814be3bc9e
BLAKE2b-256 9bd8c8d71ebd2c86120ebb8d2241ac03102e0eba2c5d943179629e7d121b33c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for imc_p4_bt-1.0.2-py3-none-any.whl:

Publisher: build.yml on rkothari3/IMC_P4_Backtester

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page