Skip to content

Commit

Permalink
adjust validate_orderbook for BB (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
Johanna Adams authored Sep 18, 2023
1 parent 40e6cac commit 118b9db
Show file tree
Hide file tree
Showing 10 changed files with 35,147 additions and 8 deletions.
11 changes: 8 additions & 3 deletions assume/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,12 @@ def separate_orders(orderbook):
# separate orders with several hours into single hour orders
delete_orders = []
for order in orderbook:
order_len = len(order["volume"]) if isinstance(order["volume"], dict) else 1
if order_len > 1:
if any([isinstance(value, dict) for value in order.values()]):
start_hour = order["start_time"]
end_hour = order["end_time"]
order_len = max(
len(value) for value in order.values() if isinstance(value, dict)
)
duration = (end_hour - start_hour) / order_len
i = 1
for start in pd.date_range(start_hour, end_hour - duration, freq=duration):
Expand All @@ -342,11 +344,14 @@ def separate_orders(orderbook):
if single_order != order:
single_order.update(
{
"bid_id": f"{order['bid_id']}_{order['bid_type']}{i}",
"start_time": start,
"end_time": start + duration,
}
)
if "bid_id" in single_order.keys():
single_order[
"bid_id"
] = f"{order['bid_id']}_{order['bid_type']}{i}"

orderbook.append(single_order)
i += 1
Expand Down
10 changes: 7 additions & 3 deletions assume/markets/base_market.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
OpeningMessage,
Orderbook,
)
from assume.common.utils import get_available_products
from assume.common.utils import get_available_products, separate_orders

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -56,6 +56,7 @@ def validate_orderbook(self, orderbook: Orderbook, agent_tuple) -> None:
if self.marketconfig.price_tick:
assert max_price is not None, "max_price unset"
assert min_price is not None, "min_price unset"
assert max_volume is not None, "max_volume unset"
# max and min should be in units
max_price = math.floor(max_price / self.marketconfig.price_tick)
min_price = math.ceil(min_price / self.marketconfig.price_tick)
Expand All @@ -67,6 +68,11 @@ def validate_orderbook(self, orderbook: Orderbook, agent_tuple) -> None:
order["agent_id"] = agent_tuple
if not order.get("only_hours"):
order["only_hours"] = None
for field in self.marketconfig.additional_fields:
assert field in order.keys(), f"missing field: {field}"

sep_orders = separate_orders(orderbook.copy())
for order in sep_orders:
assert order["price"] <= max_price, f"maximum_bid_price {order['price']}"
assert order["price"] >= min_price, f"minimum_bid_price {order['price']}"

Expand All @@ -83,8 +89,6 @@ def validate_orderbook(self, orderbook: Orderbook, agent_tuple) -> None:
assert isinstance(order["price"], int)
if self.marketconfig.volume_tick:
assert isinstance(order["volume"], int)
for field in self.marketconfig.additional_fields:
assert field in order.keys(), f"missing field: {field}"

def clear(
self, orderbook: Orderbook, market_products: list[MarketProduct]
Expand Down
4 changes: 4 additions & 0 deletions examples/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"scenario": "example_01a",
"study_case": "dam_with_complex_clearing",
},
"small_with_BB": {
"scenario": "example_01e",
"study_case": "dam_with_complex_clearing",
},
"small_with_vre": {"scenario": "example_01b", "study_case": "base"},
"small_with_vre_and_storage": {
"scenario": "example_01c",
Expand Down
46 changes: 46 additions & 0 deletions examples/inputs/example_01e/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
dam:
start_date: 2019-01-01 00:00
end_date: 2019-04-01 00:00
time_step: 1h
save_frequency_hours: 24
markets_config:
EOM:
operator: EOM_operator
product_type: energy
products:
- duration: 1h
count: 24
first_delivery: 1h
opening_frequency: 24h
opening_duration: 24h
volume_unit: MWh
maximum_bid_volume: 100000
maximum_bid_price: 3000
minimum_bid_price: -500
price_unit: EUR/MWh
market_mechanism: pay_as_clear

dam_with_complex_clearing:
start_date: 2019-01-01 00:00
end_date: 2019-04-01 00:00
time_step: 1h
save_frequency_hours: 24
markets_config:
EOM:
operator: EOM_operator
product_type: energy
products:
- duration: 1h
count: 24
first_delivery: 1h
opening_frequency: 24h
opening_duration: 24h
volume_unit: MWh
maximum_bid_volume: 100000
maximum_bid_price: 3000
minimum_bid_price: -500
price_unit: EUR/MWh
market_mechanism: pay_as_clear_complex
additional_fields:
- bid_type
- min_acceptance_ratio
Loading

0 comments on commit 118b9db

Please sign in to comment.