From 0d5e42d43066b68fea457a38379b309edd6b4395 Mon Sep 17 00:00:00 2001 From: Florian Maurer Date: Fri, 15 Sep 2023 16:12:19 +0200 Subject: [PATCH] add unused supply_orders to rejected_orders clean up setting accepted_volume and price on rejected orders fix setting the volume of the split order in clearing --- assume/markets/base_market.py | 3 +++ .../clearing_algorithms/all_or_nothing.py | 12 ------------ assume/markets/clearing_algorithms/simple.py | 16 +++++++++------- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/assume/markets/base_market.py b/assume/markets/base_market.py index e1695143..d0d33aed 100644 --- a/assume/markets/base_market.py +++ b/assume/markets/base_market.py @@ -344,6 +344,9 @@ async def clear_market(self, market_products: list[MarketProduct]): market_meta, ) = self.clear(self.all_orders, market_products) self.all_orders = [] + for order in rejected_orderbook: + order["accepted_volume"] = 0 + order["accepted_price"] = 0 self.open_auctions - set(market_products) # self.all_orders = pending_orderbook diff --git a/assume/markets/clearing_algorithms/all_or_nothing.py b/assume/markets/clearing_algorithms/all_or_nothing.py index e8060b74..f7037c03 100644 --- a/assume/markets/clearing_algorithms/all_or_nothing.py +++ b/assume/markets/clearing_algorithms/all_or_nothing.py @@ -81,12 +81,6 @@ def clear( # resulting i is the cut point accepted_product_orders.extend(demand_orders[:i]) accepted_product_orders.extend(supply_orders[:i]) - - for order in supply_orders[i:]: - order["accepted_volume"] = 0 - for order in demand_orders[i:]: - order["accepted_volume"] = 0 - rejected_orders.extend(demand_orders[i:]) rejected_orders.extend(supply_orders[i:]) @@ -168,12 +162,6 @@ def clear( accepted_product_orders.extend(demand_orders[:i]) accepted_product_orders.extend(supply_orders[:i]) - - for order in supply_orders[i:]: - order["accepted_volume"] = 0 - for order in demand_orders[i:]: - order["accepted_volume"] = 0 - rejected_orders.extend(demand_orders[i:]) rejected_orders.extend(supply_orders[i:]) diff --git a/assume/markets/clearing_algorithms/simple.py b/assume/markets/clearing_algorithms/simple.py index 95537174..ecc8d549 100644 --- a/assume/markets/clearing_algorithms/simple.py +++ b/assume/markets/clearing_algorithms/simple.py @@ -82,7 +82,6 @@ def clear( for demand_order in demand_orders: if not supply_orders: # if no more generation - reject left over demand - demand_order["accepted_volume"] = 0 rejected_orders.append(demand_order) continue @@ -100,7 +99,6 @@ def clear( to_commit.append(supply_order) gen_vol += supply_order["volume"] else: - supply_order["accepted_volume"] = 0 rejected_orders.append(supply_order) # now we know which orders we need # we only need to see how to arrange it. @@ -118,7 +116,7 @@ def clear( # generation left over - split last generation bid supply_order = to_commit[-1] split_supply_order = supply_order.copy() - split_supply_order["accepted_volume"] = diff + split_supply_order["volume"] = diff supply_order["accepted_volume"] = supply_order["volume"] - diff # changed supply_order is still part of to_commit and will be added # only volume-diff can be sold for current price @@ -133,6 +131,9 @@ def clear( accepted_product_orders.append(demand_order) accepted_product_orders.extend(to_commit) + for order in supply_orders: + rejected_orders.append(order) + # set clearing price - merit order - uniform pricing accepted_supply_orders = [ x for x in accepted_product_orders if x["accepted_volume"] > 0 @@ -204,7 +205,6 @@ def clear( for demand_order in demand_orders: if not supply_orders: # if no more generation - reject left over demand - demand_order["accepted_volume"] = 0 rejected_orders.append(demand_order) continue @@ -218,7 +218,6 @@ def clear( to_commit.append(supply_order) gen_vol += supply_order["volume"] else: - supply_order["accepted_volume"] = 0 rejected_orders.append(supply_order) # now we know which orders we need # we only need to see how to arrange it. @@ -236,8 +235,8 @@ def clear( # generation left over - split generation supply_order = to_commit[-1] split_supply_order = supply_order.copy() - split_supply_order["accepted_volume"] = diff - supply_order["accepted_volume"] -= supply_order["volume"] - diff + split_supply_order["volume"] = diff + supply_order["accepted_volume"] = supply_order["volume"] - diff # only volume-diff can be sold for current price # add left over to supply_orders again gen_vol -= diff @@ -255,6 +254,9 @@ def clear( demand_order["accepted_price"] = supply_order["price"] accepted_product_orders.extend(to_commit) + for order in supply_orders: + rejected_orders.append(order) + accepted_supply_orders = [ x for x in accepted_product_orders if x["accepted_volume"] > 0 ]