model package
Submodules
model.models
- model.models.DRL_prediction(df, model, name, last_state, iter_num, unique_trade_date, rebalance_window, turbulence_threshold, initial)
Runs the trained model on the environment for a prediction and stores the last state.
- Parameters:
df (pd.DataFrame) – The dataset used for training and validation.
model (stable_baselines3) – The trained model to use for prediction.
name (str) – The name used for saving the last state.
last_state (list) – The state from the previous prediction.
iter_num (int) – The current iteration number.
unique_trade_date (list) – A list of unique trade dates.
rebalance_window (int) – The window for rebalancing.
turbulence_threshold (float) – The threshold for turbulence.
initial (bool) – Whether this is the first iteration.
- Returns:
The last state of the environment after the prediction.
- Return type:
list
- model.models.DRL_validation(model, test_data, test_env, test_obs)
Runs the trained model for validation.
- Parameters:
model (stable_baselines3) – The trained model to use for validation.
test_data (pd.DataFrame) – The data used for testing.
test_env (gym.Env) – The environment for testing.
test_obs (np.array) – The observation for the test environment.
This function applies the trained model to the test data and environment.
- model.models.get_validation_sharpe(iteration)
Calculates the Sharpe ratio based on validation results.
- Parameters:
iteration (int) – The current iteration for validation.
- Returns:
The calculated Sharpe ratio.
- Return type:
float
- model.models.run_ensemble_strategy(df, unique_trade_date, rebalance_window, validation_window)
Runs the ensemble strategy by training multiple models (A2C, PPO, DDPG) and selecting the best performing model.
- Parameters:
df (pd.DataFrame) – The dataset used for training and validation.
unique_trade_date (list) – A list of unique trade dates.
rebalance_window (int) – The window for rebalancing.
validation_window (int) – The window for validation.
This function trains multiple models, validates them, and selects the best performing model based on Sharpe ratio. It then uses the selected model for trading predictions and stores the results.
- model.models.train_A2C(env_train, model_name, timesteps=25000)
Trains an A2C model on the given environment.
- Parameters:
env_train (gym.Env) – The environment to train the model on.
model_name (str) – The name to save the trained model.
timesteps (int, optional) – The number of timesteps to train for. Default is 25000.
- Returns:
The trained A2C model.
- Return type:
stable_baselines3.A2C
- model.models.train_DDPG(env_train, model_name, timesteps=10000)
Trains a DDPG model on the given environment.
- Parameters:
env_train (gym.Env) – The environment to train the model on.
model_name (str) – The name to save the trained model.
timesteps (int, optional) – The number of timesteps to train for. Default is 10000.
- Returns:
The trained DDPG model.
- Return type:
stable_baselines3.DDPG
- model.models.train_PPO(env_train, model_name, timesteps=50000)
Trains a PPO model on the given environment.
- Parameters:
env_train (gym.Env) – The environment to train the model on.
model_name (str) – The name to save the trained model.
timesteps (int, optional) – The number of timesteps to train for. Default is 50000.
- Returns:
The trained PPO model.
- Return type:
stable_baselines3.PPO