tensortrade.strategies.stable_baselines_strategy module

class tensortrade.strategies.stable_baselines_strategy.StableBaselinesTradingStrategy(environment, model=<class 'stable_baselines.deepq.dqn.DQN'>, policy='MlpPolicy', model_kwargs={}, **kwargs)[source]

Bases: tensortrade.strategies.trading_strategy.TradingStrategy

A trading strategy capable of self tuning, training, and evaluating with stable-baselines.

__init__(environment, model=<class 'stable_baselines.deepq.dqn.DQN'>, policy='MlpPolicy', model_kwargs={}, **kwargs)[source]
Parameters
  • environment (TradingEnvironment) – A TradingEnvironment instance for the agent to trade within.

  • model (optional) – The RL model to create the agent with. Defaults to DQN.

  • policy (optional) – The RL policy to train the agent’s model with. Defaults to ‘MlpPolicy’.

  • model_kwargs (optional) – Any additional keyword arguments to adjust the model.

  • kwargs (optional) – Optional keyword arguments to adjust the strategy.

property environment

A TradingEnvironment instance for the agent to trade within.

Return type

TradingEnvironment

restore_agent(path)[source]

Deserialize the strategy’s learning agent from a file.

Parameters

path (str) – The str path of the file the agent specification is stored in.

run(steps=None, episodes=None, episode_callback=None)[source]

Evaluate the agent’s performance within the environment.

Parameters
  • steps (Optional[int]) – The number of steps to run the agent within the environment. Required if episodes is not passed.

  • episodes (Optional[int]) – The number of episodes to run the agent within the environment. Required if steps is not passed.

  • testing – Whether or not the agent should be evaluated on the environment it is running in. Defaults to false.

  • episode_callback (optional) – A callback function for monitoring the agent’s progress within the environment.

Return type

DataFrame

Returns

A history of the agent’s trading performance during evaluation.

save_agent(path)[source]

Serialize the learning agent to a file for restoring later.

Parameters

path (str) – The str path of the file to store the agent specification in.

tune(steps=None, episodes=None, callback=None)[source]

Tune the agent’s hyper-parameters and feature set for the environment.

Parameters
  • steps_per_train – The number of steps per training of each hyper-parameter set.

  • steps_per_test – The number of steps per evaluation of each hyper-parameter set.

  • episode_callback (optional) – A callback function for monitoring progress of the tuning process.

Return type

DataFrame

Returns

A history of the agent’s trading performance during tuning.