Skip to content

Commit

Permalink
feat: all training data & compressed visual
Browse files Browse the repository at this point in the history
jmerle improved the visualizer for compression, hence
update of dontlooseshells_algo class. Also added all the
training data, for easier usage in case someone lost their
version.
  • Loading branch information
n-0 committed Mar 26, 2023
1 parent f6c7966 commit 3799374
Show file tree
Hide file tree
Showing 19 changed files with 530,342 additions and 10 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,19 @@ class Logger:
self.logs = ""
self.local = local

def print(self, *objects: Any, sep: str = " ", end: str = "\n") -> None:
self.logs += sep.join(map(str, objects)) + end

def flush(self, state: TradingState, orders: dict[Symbol, list[Order]]) -> None:
output = json.dumps({
"state": state,
"orders": orders,
"state": self.compress_state(state),
"orders": self.compress_orders(orders),
"logs": self.logs,
}, cls=ProsperityEncoder, separators=(",", ":"), sort_keys=True)
}, cls=ProsperityEncoder, separators=(",", ":"), sort_keys=True))

if self.local:
self.local_logs[state.timestamp] = output
print(output)

print(out)
self.logs = ""
# ... And the rest of the compression logic
```

and in your `Trader` class add the attribute like this:
Expand Down
5 changes: 3 additions & 2 deletions backtester.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def process_trades(df_trades, states: dict[int, TradingState], time_limit):
'', #trade['seller'],
time)
states[time].market_trades[symbol].append(t)
return states

current_limits = {
'PEARLS': 20,
Expand All @@ -123,7 +124,7 @@ def simulate_alternative(round: int, day: int, trader, time_limit=999900, end_li
df_prices = pd.read_csv(prices_path, sep=';')
df_trades = pd.read_csv(trades_path, sep=';')
states = process_prices(df_prices, time_limit)
process_trades(df_trades, states, time_limit)
states = process_trades(df_trades, states, time_limit)
position = copy.copy(states[0].position)
ref_symbols = list(states[0].position.keys())
profits_by_symbol: dict[int, dict[str, float]] = { 0: dict(zip(ref_symbols, [0.0]*len(ref_symbols))) }
Expand Down Expand Up @@ -338,7 +339,7 @@ def create_log_file(round: int, day: int, states: dict[int, TradingState], profi
if __name__ == "__main__":
trader = Trader()
max_time = int(input("Input a timestamp to end (blank for 999000): ") or 999000)
round = int(input("Input a round (blank for 3): ") or 3)
round = int(input("Input a round (blank for 4): ") or 4)
day = int(input("Input a day (blank for random): ") or random.randint(0, 2))
halfway = bool(input("Matching orders halfway (sth. not blank for True): ")) or False
liqudation = bool(input("Should all positions be liquidated in the final run (sth. not blank for True): ")) or False
Expand Down
44 changes: 43 additions & 1 deletion dontlooseshells_algo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from datamodel import Order, ProsperityEncoder, Symbol, TradingState
from datamodel import Order, ProsperityEncoder, Symbol, TradingState, Trade
from typing import Any

class Logger:
Expand Down Expand Up @@ -29,6 +29,48 @@ def flush(self, state: TradingState, orders: dict[Symbol, list[Order]]) -> None:

self.logs = ""

def compress_state(self, state: TradingState) -> dict[str, Any]:
listings = []
for listing in state.listings.values():
listings.append([listing["symbol"], listing["product"], listing["denomination"]])

order_depths = {}
for symbol, order_depth in state.order_depths.items():
order_depths[symbol] = [order_depth.buy_orders, order_depth.sell_orders]

return {
"t": state.timestamp,
"l": listings,
"od": order_depths,
"ot": self.compress_trades(state.own_trades),
"mt": self.compress_trades(state.market_trades),
"p": state.position,
"o": state.observations,
}

def compress_trades(self, trades: dict[Symbol, list[Trade]]) -> list[list[Any]]:
compressed = []
for arr in trades.values():
for trade in arr:
compressed.append([
trade.symbol,
trade.buyer,
trade.seller,
trade.price,
trade.quantity,
trade.timestamp,
])

return compressed

def compress_orders(self, orders: dict[Symbol, list[Order]]) -> list[list[Any]]:
compressed = []
for arr in orders.values():
for order in arr:
compressed.append([order.symbol, order.price, order.quantity])

return compressed

# This is provisionary, if no other algorithm works.
# Better to loose nothing, then dreaming of a gain.
class Trader:
Expand Down
20,001 changes: 20,001 additions & 0 deletions training/prices_round_1_day_-1.csv

Large diffs are not rendered by default.

20,001 changes: 20,001 additions & 0 deletions training/prices_round_1_day_-2.csv

Large diffs are not rendered by default.

20,001 changes: 20,001 additions & 0 deletions training/prices_round_1_day_0.csv

Large diffs are not rendered by default.

40,001 changes: 40,001 additions & 0 deletions training/prices_round_2_day_-1.csv

Large diffs are not rendered by default.

40,001 changes: 40,001 additions & 0 deletions training/prices_round_2_day_1.csv

Large diffs are not rendered by default.

110,001 changes: 110,001 additions & 0 deletions training/prices_round_4_day_1.csv

Large diffs are not rendered by default.

110,001 changes: 110,001 additions & 0 deletions training/prices_round_4_day_2.csv

Large diffs are not rendered by default.

110,001 changes: 110,001 additions & 0 deletions training/prices_round_4_day_3.csv

Large diffs are not rendered by default.

Loading

0 comments on commit 3799374

Please sign in to comment.