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.3.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.3-py3-none-any.whl (1.8 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: imc_p4_bt-1.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 f498d84da1ac8c5859201288db79c5963627396d7b7e27ee7517f1990d9b9a99
MD5 be26b2e2705f0c6236943c77db53639d
BLAKE2b-256 2fb1fbe9f12840b5266120b6773ca4874a42ed048fb855b35ab71599bda1eca2

See more details on using hashes here.

Provenance

The following attestation bundles were made for imc_p4_bt-1.0.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: imc_p4_bt-1.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ab0abce8fcc75631694e20b0c798f5f056d6c225c1a39163b18f68ce8ddaaaed
MD5 cdbff2a07c8f3ee0237be43818768c03
BLAKE2b-256 2d2f9305f65eb739e52a6dc3df704ba3fe3127fe0fa1e86039f65d17f3053eb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for imc_p4_bt-1.0.3-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