-
Notifications
You must be signed in to change notification settings - Fork 1
/
evaluation.py
105 lines (84 loc) · 3.39 KB
/
evaluation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# SPDX-FileCopyrightText: ASSUME Developers
#
# SPDX-License-Identifier: AGPL-3.0-or-later
from datetime import datetime, timedelta
from dateutil import rrule as rr
from dateutil.relativedelta import relativedelta as rd
from emarketlib.clearing_algorithms.simple import PayAsClearRole
from emarketlib.market_objects import MarketConfig, MarketProduct
from emarketlib.utils import (
get_available_products,
plot_orderbook,
)
from tests.utils import extend_orderbook
simple_dayahead_auction_config = MarketConfig(
market_id="simple_dayahead_auction",
market_products=[MarketProduct(rd(hours=+1), 1, rd(hours=1))],
additional_fields=["node"],
opening_hours=rr.rrule(
rr.HOURLY,
dtstart=datetime(2005, 6, 1),
cache=True,
),
opening_duration=timedelta(hours=1),
volume_unit="MW",
volume_tick=0.1,
price_unit="€/MW",
market_mechanism="pay_as_clear",
)
next_opening = simple_dayahead_auction_config.opening_hours.after(datetime.now())
products = get_available_products(
simple_dayahead_auction_config.market_products, next_opening
)
# vertical down
orderbook = extend_orderbook(products, -100, 100)
orderbook = extend_orderbook(products, -100, 50, orderbook)
orderbook = extend_orderbook(products, 100, 70, orderbook)
orderbook = extend_orderbook(products, 100, 80, orderbook)
mr = PayAsClearRole(simple_dayahead_auction_config)
accepted, rejected, meta, _ = mr.clear(orderbook, products)
all_orders = []
all_orders.extend(accepted)
all_orders.extend(rejected)
plot_orderbook(all_orders, meta, "vertical overlap", show_text=False)
### intersect demand change
orderbook = extend_orderbook(products, -100, 100)
orderbook = extend_orderbook(products, -100, 10, orderbook)
orderbook = extend_orderbook(products, 80, 120, orderbook)
orderbook = extend_orderbook(products, 120, 80, orderbook)
mr = PayAsClearRole(simple_dayahead_auction_config)
accepted, rejected, meta, _ = mr.clear(orderbook, products)
all_orders = []
all_orders.extend(accepted)
all_orders.extend(rejected)
plot_orderbook(all_orders, meta, "intersection demand change", show_text=False)
### intersect supply change
orderbook = extend_orderbook(products, -100, 100)
orderbook = extend_orderbook(products, -100, 10, orderbook)
orderbook = extend_orderbook(products, 50, 50, orderbook)
orderbook = extend_orderbook(products, 150, 80, orderbook)
mr = PayAsClearRole(simple_dayahead_auction_config)
accepted, rejected, meta, _ = mr.clear(orderbook, products)
all_orders = []
all_orders.extend(accepted)
all_orders.extend(rejected)
plot_orderbook(all_orders, meta, "intersection supply change", show_text=False)
### intersect more expensive price
orderbook = extend_orderbook(products, -100, 100)
orderbook = extend_orderbook(products, -90, 50, orderbook)
orderbook = extend_orderbook(products, -100, 3, orderbook)
orderbook = extend_orderbook(products, 100, 3, orderbook)
orderbook = extend_orderbook(products, 100, 50, orderbook)
orderbook = extend_orderbook(products, 100, 100, orderbook)
mr = PayAsClearRole(simple_dayahead_auction_config)
accepted, rejected, meta, _ = mr.clear(orderbook, products)
all_orders = []
all_orders.extend(accepted)
all_orders.extend(rejected)
plot_orderbook(all_orders, meta, "horizontal overlap", show_text=False)
assert meta[0]["demand_volume"] > 0
assert meta[0]["price"] > 0
import pandas as pd # noqa: E402
print(pd.DataFrame(all_orders))
print(pd.DataFrame(accepted))
print(meta)