Skip to content

Commit

Permalink
this fixes market clearing if more supply is available
Browse files Browse the repository at this point in the history
tests for verification are added
  • Loading branch information
maurerle committed Sep 29, 2023
1 parent b6e1e9c commit ff6eacd
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
6 changes: 4 additions & 2 deletions assume/markets/clearing_algorithms/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,17 @@ def clear(
gen_vol -= diff

# add left over to supply_orders again
# supply_orders.insert(0, supply_order)
supply_orders.insert(0, supply_order)
demand_order["accepted_volume"] = demand_order["volume"]
else:
demand_order["accepted_volume"] = demand_order["volume"]

accepted_demand_orders.append(demand_order)

for order in supply_orders:
rejected_orders.append(order)
# if the order was not accepted partially, it is rejected
if not order.get("accepted_volume"):
rejected_orders.append(order)

# set clearing price - merit order - uniform pricing
if accepted_supply_orders:
Expand Down
66 changes: 66 additions & 0 deletions tests/test_simple_market_mechanisms.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,75 @@ def test_market_pay_as_clear():
orderbook = extend_orderbook(products, 300, 100, orderbook)
orderbook = extend_orderbook(products, 200, 50, orderbook)

mr = PayAsClearRole(simple_dayahead_auction_config)
accepted, rejected, meta = mr.clear(orderbook, products)
assert meta[0]["demand_volume"] > 0
assert meta[0]["price"] > 0
assert len(accepted) == 4
assert len(rejected) == 0
assert meta[0]["supply_volume"] == 500
assert meta[0]["demand_volume"] == 500
assert meta[0]["price"] == 100
for bid in accepted:
assert bid["volume"] == bid["accepted_volume"]


def test_market_pay_as_clears_single_demand():
next_opening = simple_dayahead_auction_config.opening_hours.after(datetime.now())
products = get_available_products(
simple_dayahead_auction_config.market_products, next_opening
)
assert len(products) == 1

"""
Create Orderbook with constant order volumes and prices:
- dem1: volume = -1000, price = 3000
- gen1: volume = 1000, price = 100
- gen2: volume = 900, price = 50
"""
orderbook = extend_orderbook(products, -700, 3000)
orderbook = extend_orderbook(products, 300, 100, orderbook)
orderbook = extend_orderbook(products, 200, 50, orderbook)

mr = PayAsClearRole(simple_dayahead_auction_config)
accepted, rejected, meta = mr.clear(orderbook, products)
assert meta[0]["demand_volume"] > 0
assert meta[0]["price"] > 0
assert len(accepted) == 3
assert len(rejected) == 0
assert meta[0]["supply_volume"] == 500
assert meta[0]["demand_volume"] == 500
assert meta[0]["price"] == 100
assert accepted[0]["volume"] == -700
assert accepted[0]["accepted_volume"] == -500


def test_market_pay_as_clears_single_demand_more_generation():
next_opening = simple_dayahead_auction_config.opening_hours.after(datetime.now())
products = get_available_products(
simple_dayahead_auction_config.market_products, next_opening
)
assert len(products) == 1

"""
Create Orderbook with constant order volumes and prices:
- dem1: volume = -1000, price = 3000
- gen1: volume = 1000, price = 100
- gen2: volume = 900, price = 50
"""
orderbook = extend_orderbook(products, -400, 3000)
orderbook = extend_orderbook(products, 300, 100, orderbook)
orderbook = extend_orderbook(products, 200, 50, orderbook)
orderbook = extend_orderbook(products, 230, 60, orderbook)

mr = PayAsClearRole(simple_dayahead_auction_config)
accepted, rejected, meta = mr.clear(orderbook, products)
assert meta[0]["demand_volume"] > 0
assert meta[0]["price"] > 0
assert len(accepted) == 3
assert len(rejected) == 1
assert meta[0]["supply_volume"] == 400
assert meta[0]["demand_volume"] == 400
assert meta[0]["price"] == 60
assert accepted[0]["volume"] == -400
assert accepted[0]["accepted_volume"] == -400

0 comments on commit ff6eacd

Please sign in to comment.