Skip to content

Commit

Permalink
Merge pull request #260 from assume-framework/storage_strategy
Browse files Browse the repository at this point in the history
fix calculation of flexable storage bids
  • Loading branch information
Johanna Adams authored Dec 20, 2023
2 parents dd9a744 + cfaf842 commit 3a86cab
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 21 deletions.
11 changes: 5 additions & 6 deletions assume/strategies/flexable_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,19 @@ def calculate_bids(
price_forecast=price_forecast,
)

if price_forecast[start] >= average_price / unit.efficiency_discharge:
if price_forecast[start] >= average_price:
price = average_price / unit.efficiency_discharge
bid_quantity = max_power_discharge[start]
elif price_forecast[start] <= average_price * unit.efficiency_charge:
bid_quantity = max_power_charge[start]
else:
previous_power = current_power
continue
price = average_price * unit.efficiency_charge
bid_quantity = max_power_charge[start]

bids.append(
{
"start_time": start,
"end_time": end,
"only_hours": None,
"price": average_price,
"price": price,
"volume": bid_quantity,
}
)
Expand Down
74 changes: 59 additions & 15 deletions tests/test_flexable_storage_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ def test_flexable_eom_storage(mock_market_config, storage):
storage.forecaster = NaiveForecast(index, availability=1, price_forecast=50)
bids = strategy.calculate_bids(storage, mc, product_tuples=product_tuples)
# no change in price forecast -> no bidding
assert bids == []
assert len(bids) == 1
assert bids[0]["price"] == 50 / storage.efficiency_discharge
assert bids[0]["volume"] == 60

# increase the current price forecast -> discharging
storage.forecaster = NaiveForecast(
index, availability=1, price_forecast=[60, 50, 50, 50]
)
bids = strategy.calculate_bids(storage, mc, product_tuples=product_tuples)
assert len(bids) == 1
assert bids[0]["price"] == 52.5
assert bids[0]["price"] == 52.5 / storage.efficiency_discharge
assert bids[0]["volume"] == 60

# decrease current price forecast -> charging
Expand All @@ -74,7 +76,7 @@ def test_flexable_eom_storage(mock_market_config, storage):
)
bids = strategy.calculate_bids(storage, mc, product_tuples=product_tuples)
assert len(bids) == 1
assert bids[0]["price"] == 47.5
assert bids[0]["price"] == 47.5 * storage.efficiency_charge
assert bids[0]["volume"] == -60

# change to dam bidding
Expand Down Expand Up @@ -110,19 +112,61 @@ def test_flexable_eom_storage(mock_market_config, storage):
]
storage.forecaster = NaiveForecast(index, availability=1, price_forecast=forecast)
bids = strategy.calculate_bids(storage, mc, product_tuples=product_tuples)
assert len(bids) == 6
assert math.isclose(bids[0]["price"], np.mean(forecast[0:13]), abs_tol=0.01)
assert len(bids) == 24
assert math.isclose(
bids[0]["price"],
np.mean(forecast[0:13]) * storage.efficiency_charge,
abs_tol=0.01,
)
assert bids[0]["volume"] == -60
assert math.isclose(bids[1]["price"], np.mean(forecast[0:17]), abs_tol=0.01)
assert bids[1]["volume"] == 60
assert math.isclose(bids[2]["price"], np.mean(forecast[0:21]), abs_tol=0.01)
assert bids[2]["volume"] == 60
assert math.isclose(bids[3]["price"], np.mean(forecast[0:25]), abs_tol=0.01)
assert bids[3]["volume"] == 60
assert math.isclose(bids[4]["price"], np.mean(forecast[4:]), abs_tol=0.01)
assert bids[4]["volume"] == -60
assert math.isclose(bids[5]["price"], np.mean(forecast[8:]), abs_tol=0.01)
assert bids[5]["volume"] == -60
assert math.isclose(
bids[1]["price"],
np.mean(forecast[0:14]) * storage.efficiency_charge,
abs_tol=0.01,
)
assert bids[1]["volume"] == -100
assert math.isclose(
bids[2]["price"],
np.mean(forecast[0:15]) * storage.efficiency_charge,
abs_tol=0.01,
)
assert bids[2]["volume"] == -100
assert math.isclose(
bids[3]["price"],
np.mean(forecast[0:16]) * storage.efficiency_charge,
abs_tol=0.01,
)
assert bids[3]["volume"] == -100
assert math.isclose(
bids[4]["price"],
np.mean(forecast[0:17]) / storage.efficiency_discharge,
abs_tol=0.01,
)
assert bids[4]["volume"] == 0
assert math.isclose(
bids[8]["price"],
np.mean(forecast[0:21]) / storage.efficiency_discharge,
abs_tol=0.01,
)
assert math.isclose(bids[8]["volume"], 14.444, abs_tol=0.01)
assert math.isclose(
bids[12]["price"],
np.mean(forecast[0:25]) / storage.efficiency_discharge,
abs_tol=0.01,
)
assert bids[12]["volume"] == 100
assert math.isclose(
bids[16]["price"],
np.mean(forecast[4:]) * storage.efficiency_charge,
abs_tol=0.01,
)
assert bids[16]["volume"] == -100
assert math.isclose(
bids[20]["price"],
np.mean(forecast[8:]) * storage.efficiency_charge,
abs_tol=0.01,
)
assert bids[20]["volume"] == 0


def test_flexable_pos_crm_storage(mock_market_config, storage):
Expand Down

0 comments on commit 3a86cab

Please sign in to comment.