Metadata-Version: 2.1
Name: prosperity2bt
Version: 0.3.1
Summary: Backtester for IMC Prosperity 2 algorithms
Author-email: Jasper van Merle <jaspervmerle@gmail.com>
License: MIT License
        
        Copyright (c) 2024 Jasper van Merle
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Repository, https://github.com/jmerle/imc-prosperity-2-backtester
Project-URL: Issues, https://github.com/jmerle/imc-prosperity-2-backtester/issues
Project-URL: Changelog, https://github.com/jmerle/imc-prosperity-2-backtester/releases
Keywords: imc,prosperity,backtest,backtester
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: ipython
Requires-Dist: jsonpickle

# IMC Prosperity 2 Backtester

[![Build Status](https://github.com/jmerle/imc-prosperity-2-backtester/workflows/Build/badge.svg)](https://github.com/jmerle/imc-prosperity-2-backtester/actions/workflows/build.yml)
[![PyPI Version](https://img.shields.io/pypi/v/prosperity2bt)](https://pypi.org/project/prosperity2bt/)

This repository contains a backtester [IMC Prosperity 2](https://prosperity.imc.com/) algorithms. The output it generates closely matches the format of the output generated by the official submission environment and is therefore compatible with my [IMC Prosperity 2 Visualizer](https://github.com/jmerle/imc-prosperity-2-visualizer) (assuming your code contains the visualizer's required prerequisites as explained on the visualizer's homepage).

## Usage

Basic usage:
```sh
# Install the latest version of the backtester
$ pip install -U prosperity2bt

# Run the backtester on an algorithm using all data from round 0
$ prosperity2bt <path to algorithm file> 0
```

Run `pip install -U prosperity2bt` again when you want to update the backtester to the latest version.

Some more usage examples:
```sh
# Backtest on all days from round 1
$ prosperity2bt example/starter.py 1

# Backtest on round 1 day 0
$ prosperity2bt example/starter.py 1-0

# Backtest on round 1 day -1 and round 1 day 0
$ prosperity2bt example/starter.py 1--1 1-0

# Backtest on all days from rounds 1 and 2
$ prosperity2bt example/starter.py 1 2

# You get the idea

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

# Automatically open the result in the visualizer when done
# Assumes your algorithm logs in the visualizer's expected format
$ prosperity2bt example/starter.py 1 --vis

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

# Backtest on custom data
# Requires the value passed to `--data` to be a path to a directory that is similar in structure to https://github.com/jmerle/imc-prosperity-2-backtester/tree/master/prosperity2bt/resources
$ prosperity2bt example/starter.py 1 --data prosperity2bt/resources

# Print trader's output to stdout while running
# This may be helpful when debugging a broken trader
$ prosperity2bt example/starter.py 1 --print
```

## Order Matching

Orders placed by `Trader.run` at a given timestamp are matched against the order depths of that timestamp's state. Market trades are ignored in the matching process. Orders are executed at your best possible price, e.g. if you place a buy order for €10 but there is non-zero ask volume at €9, your order is (possibly partially) filled at €9. Similarly, if you place a sell order for €10 but there is non-zero bid volume at €11, your order is (possibly partially) filled at €11.

Limits are enforced before orders are matched to order depths. If for a product your position would exceed the limit, assuming all your orders would get filled, all your orders for that product get canceled.

## Development

If you want to make changes to the backtester, clone (or fork and clone) this repository and run `pip install -e .` in the project's root. This installs the project in editable mode, so any changes you make are automatically taken into account the next time you run `prosperity2bt`.
