Skip to content

Commit

Permalink
Resource bot mixing price (#65)
Browse files Browse the repository at this point in the history
* Tests fix

* Add import

* Fixed comments

* Fix tests

* Add dataset futures script

* Add price mixing

* Formatting

* Price weight

* Fix tests
  • Loading branch information
nitko12 authored Mar 1, 2024
1 parent 7c2dd8c commit b17c435
Show file tree
Hide file tree
Showing 28 changed files with 166,200 additions and 65,294 deletions.
1 change: 1 addition & 0 deletions backend/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ bots:
max_price_change: 20
expiration_ticks: 5
price_change_coeff: 0.05
dataset_price_weight: 0.5

max_energy_per_player: 0.2

Expand Down
2,332 changes: 0 additions & 2,332 deletions backend/data/df_2331_2009-05-05 08:30:00_2009-08-10 10:30:00.csv

This file was deleted.

2,432 changes: 2,432 additions & 0 deletions backend/data/df_2431_2011-11-06 03:30:00_2012-02-15 09:30:00.csv

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion backend/db/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ async def run_migrations():
biomass INT NOT NULL,
gas INT NOT NULL,
oil INT NOT NULL,
coal_price INT NOT NULL,
uranium_price INT NOT NULL,
biomass_price INT NOT NULL,
gas_price INT NOT NULL,
oil_price INT NOT NULL,
geothermal INT NOT NULL,
wind INT NOT NULL,
solar INT NOT NULL,
Expand Down Expand Up @@ -230,7 +235,12 @@ async def run_migrations():
solar=row["SOLAR"],
hydro=row["HYDRO"],
energy_demand=row["ENERGY_DEMAND"],
max_energy_price=row["MAX_ENERGY_PRICE"]
max_energy_price=row["MAX_ENERGY_PRICE"],
coal_price=row["COAL_PRICE"],
uranium_price=row["URANIUM_PRICE"],
biomass_price=row["BIOMASS_PRICE"],
gas_price=row["GAS_PRICE"],
oil_price=row["OIL_PRICE"]
)
i += 1
logger.info(f"Added dataset {x}")
Expand Down
12 changes: 12 additions & 0 deletions backend/game/bots/resource_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
price_change_coeff = config['bots']['price_change_coeff']
max_price_change = config['bots']['max_price_change']
expiration_ticks = config['bots']['expiration_ticks']
dataset_price_weight = config['bots']['dataset_price_weight']


class ResourceBot(Bot):
Expand Down Expand Up @@ -49,6 +50,9 @@ async def run(self, tick_data: TickData):
orders = await self.get_last_orders()

for resource in Resource:
if resource == Resource.energy:
continue

resource_orders = orders[resource]
resource_sum = resources_sum[resource]
buy_price = self.buy_prices[resource]
Expand Down Expand Up @@ -79,11 +83,19 @@ async def run(self, tick_data: TickData):
if buy_price == sell_price:
buy_price = sell_price - 1

buy_price = self.mix_dataset_price(
tick_data.dataset_row, buy_price, resource)
sell_price = self.mix_dataset_price(
tick_data.dataset_row, sell_price, resource)

await self.create_orders(tick_data.game.current_tick,
resource, buy_price, sell_price, buy_volume, sell_volume)
self.buy_prices[resource] = buy_price
self.sell_prices[resource] = sell_price

def mix_dataset_price(self, dataset_row, price, resource):
return dataset_price_weight * dataset_row[resource.name.lower() + "_price"] + (1 - dataset_price_weight) * price

def get_filled_perc(self, orders: List[Order]):
size = {side: 0 for side in OrderSide}
filled_size = {side: 0 for side in OrderSide}
Expand Down
12 changes: 11 additions & 1 deletion backend/game/fixtures/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ def dataset_row():
solar=8,
hydro=9,
energy_demand=100,
max_energy_price=1000
max_energy_price=1000,
coal_price=1,
uranium_price=2,
biomass_price=3,
gas_price=4,
oil_price=5,
)


Expand Down Expand Up @@ -96,6 +101,11 @@ def get_tick_data(markets, players, user_cancelled_orders=[], pending_orders=[],
biomass=3,
gas=4,
oil=5,
coal_price=coal,
uranium_price=2,
biomass_price=3,
gas_price=4,
oil_price=5,
geothermal=6,
wind=7,
solar=8,
Expand Down
5 changes: 5 additions & 0 deletions backend/model/dataset_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class DatasetData(Table):
wind: int
solar: int
hydro: int
coal_price: int
uranium_price: int
biomass_price: int
gas_price: int
oil_price: int
energy_demand: int
max_energy_price: int

Expand Down
15 changes: 15 additions & 0 deletions backend/model/test_datasets_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ def sample_dataset_data():
wind=40,
solar=60,
hydro=25,
coal_price=100,
uranium_price=50,
biomass_price=30,
gas_price=80,
oil_price=70,
energy_demand=300,
max_energy_price=70
)
Expand All @@ -39,6 +44,11 @@ def test_dataset_data_initialization(sample_dataset_data):
assert sample_dataset_data.hydro == 25
assert sample_dataset_data.energy_demand == 300
assert sample_dataset_data.max_energy_price == 70
assert sample_dataset_data.coal_price == 100
assert sample_dataset_data.uranium_price == 50
assert sample_dataset_data.biomass_price == 30
assert sample_dataset_data.gas_price == 80
assert sample_dataset_data.oil_price == 70


def test_dataset_data_indexing(sample_dataset_data):
Expand All @@ -53,3 +63,8 @@ def test_dataset_data_indexing(sample_dataset_data):
assert sample_dataset_data['Hydro'] == 25
assert sample_dataset_data['energy_demand'] == 300
assert sample_dataset_data['max_energy_price'] == 70
assert sample_dataset_data['coal_price'] == 100
assert sample_dataset_data['uranium_price'] == 50
assert sample_dataset_data['biomass_price'] == 30
assert sample_dataset_data['gas_price'] == 80
assert sample_dataset_data['oil_price'] == 70
Loading

0 comments on commit b17c435

Please sign in to comment.