Skip to content

Commit 092b828

Browse files
authored
Portfolio rl strategy (#758)
2 parents 35e5f41 + 3939bc0 commit 092b828

File tree

7 files changed

+583
-31
lines changed

7 files changed

+583
-31
lines changed

assume/reinforcement_learning/learning_utils.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,32 @@ def transfer_weights(
336336
)
337337

338338
return new_state_copy
339+
340+
341+
def encode_time_features(start: datetime) -> list:
342+
"""
343+
Encode time features for a given datetime object.
344+
This function extracts various time-related features from the datetime object
345+
and encodes them using sine and cosine transformations to capture periodicity.
346+
347+
Args:
348+
start (datetime): The datetime object to encode.
349+
350+
Returns:
351+
list: A list containing the encoded time features.
352+
"""
353+
354+
start_hour = start.hour / 24.0
355+
start_hour_cos = np.cos(2 * np.pi * start_hour)
356+
start_hour_sin = np.sin(2 * np.pi * start_hour)
357+
358+
start_month = start.month / 12.0
359+
start_month_cos = np.cos(2 * np.pi * start_month)
360+
start_month_sin = np.sin(2 * np.pi * start_month)
361+
362+
return (
363+
start_hour_cos,
364+
start_hour_sin,
365+
start_month_cos,
366+
start_month_sin,
367+
)

assume/strategies/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@
120120
RenewableEnergyLearningSingleBidStrategy
121121
)
122122

123+
from assume.strategies.portfolio_learning_strategies import (
124+
PortfolioLearningStrategy,
125+
)
123126

127+
bidding_strategies["portfolio_learning"] = PortfolioLearningStrategy
124128
except ImportError:
125129
pass

assume/strategies/learning_strategies.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,6 @@ class EnergyLearningStrategy(TorchLearningStrategy, MinMaxStrategy):
349349
Number of time steps for which the agent forecasts market conditions. Defaults to 12.
350350
max_bid_price : float
351351
Maximum allowable bid price. Defaults to 100.
352-
max_demand : float
353-
Maximum demand capacity of the unit. Defaults to 10e3.
354352
device : str
355353
Device for computation, such as "cpu" or "cuda". Defaults to "cpu".
356354
float_type : str
@@ -363,8 +361,6 @@ class EnergyLearningStrategy(TorchLearningStrategy, MinMaxStrategy):
363361
Class of the neural network architecture used for the actor network. Defaults to MLPActor.
364362
actor : torch.nn.Module
365363
Actor network for determining actions.
366-
order_types : list[str]
367-
Types of market orders supported by the strategy. Defaults to ["SB"].
368364
action_noise : NormalActionNoise
369365
Noise model added to actions during learning to encourage exploration. Defaults to None.
370366
collect_initial_experience_mode : bool
@@ -390,9 +386,6 @@ def __init__(self, *args, **kwargs):
390386
**kwargs,
391387
)
392388

393-
# define allowed order types
394-
self.order_types = kwargs.get("order_types", ["SB"])
395-
396389
def calculate_bids(
397390
self,
398391
unit: SupportsMinMax,
@@ -835,8 +828,6 @@ class StorageEnergyLearningStrategy(TorchLearningStrategy, MinMaxChargeStrategy)
835828
Number of time steps for forecasting market conditions. Defaults to 24.
836829
max_bid_price : float
837830
Maximum allowable bid price. Defaults to 100.
838-
max_demand : float
839-
Maximum demand capacity of the storage. Defaults to 10e3.
840831
device : str
841832
Device used for computation ("cpu" or "cuda"). Defaults to "cpu".
842833
float_type : str
@@ -849,8 +840,6 @@ class StorageEnergyLearningStrategy(TorchLearningStrategy, MinMaxChargeStrategy)
849840
Class of the neural network for the actor network. Defaults to MLPActor.
850841
actor : torch.nn.Module
851842
The neural network used to predict actions.
852-
order_types : list[str]
853-
Types of market orders used by the strategy. Defaults to ["SB"].
854843
action_noise : NormalActionNoise
855844
Noise model added to actions during learning for exploration. Defaults to None.
856845
collect_initial_experience_mode : bool
@@ -876,9 +865,6 @@ def __init__(self, *args, **kwargs):
876865
**kwargs,
877866
)
878867

879-
# define allowed order types
880-
self.order_types = kwargs.get("order_types", ["SB"])
881-
882868
def get_individual_observations(
883869
self, unit: SupportsMinMaxCharge, start: datetime, end: datetime
884870
):
@@ -1146,8 +1132,6 @@ class RenewableEnergyLearningSingleBidStrategy(EnergyLearningSingleBidStrategy):
11461132
Class of the neural network for the actor network. Defaults to MLPActor.
11471133
actor : torch.nn.Module
11481134
The neural network used to predict actions.
1149-
order_types : list[str]
1150-
Types of market orders used by the strategy. Defaults to ["SB"].
11511135
action_noise : NormalActionNoise
11521136
Noise model added to actions during learning for exploration. Defaults to None.
11531137
collect_initial_experience_mode : bool
@@ -1173,9 +1157,6 @@ def __init__(self, *args, **kwargs):
11731157
**kwargs,
11741158
)
11751159

1176-
# define allowed order types
1177-
self.order_types = kwargs.get("order_types", ["SB"])
1178-
11791160
def get_individual_observations(
11801161
self, unit: SupportsMinMaxCharge, start: datetime, end: datetime
11811162
):

0 commit comments

Comments
 (0)