base_environment
Classes
Base trading environment for reinforcement learning agents. |
Module Contents
- class base_environment.BaseTradingEnv(data, cfg, features, time_step=(TimeFrameUnit.Day, 1))
Bases:
gymnasium.Env,abc.ABCBase trading environment for reinforcement learning agents. Contains common functionality shared between training and testing environments.
- Parameters:
data (pandas.DataFrame)
features (List[trading.src.features.generic_features.Feature])
time_step (tuple[alpaca.data.timeframe.TimeFrameUnit, int])
- symbols
- stock_dimension
- features
- feature_cols
- time_step
- action_space
- observation_space
- observation_index
- terminal = False
- observation_timestamp = None
- init_data(data)
Set the data for the environment. :param data: DataFrame containing the trading data.
- Parameters:
data (pandas.DataFrame)
- classmethod observation(df, portfolio_state, feature_cols, prices)
Build observation from dataframe, portfolio state, and prices.
- Parameters:
df (pandas.DataFrame)
portfolio_state (numpy.ndarray)
feature_cols (list)
prices (numpy.ndarray)
- Return type:
numpy.ndarray
- _get_observation_df(i=-1)
Get the dataframe slice for observation at index i.
- Parameters:
i (int)
- Return type:
pandas.DataFrame
- _get_prices(i=-1)
Get prices at index i.
- Parameters:
i (int)
- Return type:
numpy.ndarray
- abstractmethod _get_observation(i=-1)
Get the current observation from the environment.
- Parameters:
i (int)
- Return type:
numpy.ndarray
- reset(*, seed=None, options=None)
Reset the environment to its initial state. Can be overridden by subclasses.
- Parameters:
seed (Optional[int])
options (Optional[dict])
- abstractmethod step(action)
Execute one time step within the environment.
- render()
Render the environment state.
- _reset_internal_states(timestamp=None)
Reset internal state counters.
- Parameters:
timestamp (pandas.Timestamp | None)