Our team placed in the top 9% of Prosperity 3!
https://imc-prosperity.notion.site/Writing-an-Algorithm-in-Python-19ee8453a0938114a15eca1124bf28a1
The class only requires a single method called run
, which is called by the simulation every time a new TraderState
is available. The logic within this run
method is written by the player and determines the behaviour of the algorithm. The output of the method is a dictionary named result
, which contains all the orders that the algorithm decides to send based on this logic.
For the following example we assume a situation with two products:
- PRODUCT1 with position limit 10
- PRODUCT2 with position limit 20
At the start of the first iteration the run method is called with the TradingState
generated by the below code. Note: the datamodel.py file from which the classes are imported is provided in Appendix B. The code can also be used to test algorithms locally.
from datamodel import Listing, OrderDepth, Trade, TradingState
timestamp = 1000
listings = { "PRODUCT1": Listing( symbol="PRODUCT1", product="PRODUCT1", denomination= "SEASHELLS" ), "PRODUCT2": Listing( symbol="PRODUCT2", product="PRODUCT2", denomination= "SEASHELLS" ), }
order_depths = { "PRODUCT1": OrderDepth( buy_orders={10: 7, 9: 5}, sell_orders={11: -4, 12: -8} ), "PRODUCT2": OrderDepth( buy_orders={142: 3, 141: 5}, sell_orders={144: -5, 145: -8} ), }
own_trades = { "PRODUCT1": [], "PRODUCT2": [] }
market_trades = { "PRODUCT1": [ Trade( symbol="PRODUCT1", price=11, quantity=4, buyer="", seller="", timestamp=900 ) ], "PRODUCT2": [] }
position = { "PRODUCT1": 3, "PRODUCT2": -5 }
observations = {} traderData = ""
state = TradingState( traderData, timestamp, listings, order_depths, own_trades, market_trades, position, observations )