tensortrade.strategies.trading_strategy module

class tensortrade.strategies.trading_strategy.TradingStrategy(environment)[source]

Bases: object

An abstract trading strategy capable of self tuning, training, and evaluating.

abstract __init__(environment)[source]
Parameters

environment (TradingEnvironment) – A TradingEnvironment instance for the agent to trade within.

property environment

A TradingEnvironment instance for the agent to trade within.

Return type

TradingEnvironment

abstract restore_agent(path)[source]

Deserialize the strategy’s learning agent from a file.

Parameters

path (str) – The str path of where the strategy is stored.

abstract run(steps=None, episodes=None, testing=False, 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 (bool) – 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.

abstract save_agent(path)[source]

Serialize the strategy’s learning agent to a file for restoring later.

Parameters

path (str) – The str path of where to store the strategy.

abstract tune(steps_per_train, steps_per_test, episode_callback=None)[source]

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

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

  • steps_per_test (int) – 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.