tensortrade.agents.trading_agent module

class tensortrade.agents.trading_agent.TradingAgent(env, feature_pipeline)[source]

Bases: object

An abstract base class for trading agents capable of self tuning, training, and evaluating.

property env

A TradingEnvironment instance for the agent to trade within.

abstract evaluate(steps, callback)[source]

Evaluate the agent’s performance within the environment.

Parameters
  • steps (int) – The number of steps to train the model within the environment.

  • step_cb (optional) – A callback function for monitoring progress of the evaluation process. step_cb(pd.DataFrame) -> bool: A history of the agent’s trading performance is passed on each iteration. If the callback returns True, the training process will stop early.

Return type

pandas.DataFrame

Returns

A history of the agent’s trading performance during evaluation

property feature_pipeline

A FeaturePipeline instance of feature transformations.

abstract get_action(observation)[source]

Determine an action based on a specific observation.

Parameters

observation (pandas.DataFrame) – A pandas.DataFrame corresponding to an observation within the environment.

Return type

Union[float, List[float]]

Returns

An action whose type depends on the action space of the environment.

abstract train(steps, callback)[source]

Train the agent’s underlying model on the environment.

Parameters
  • steps (int) – The number of steps to train the model within the environment.

  • step_cb (optional) – A callback function for monitoring progress of the training process. step_cb(pd.DataFrame) -> bool: A history of the agent’s trading performance is passed on each iteration. If the callback returns True, the training process will stop early.

Return type

pandas.DataFrame

Returns

A history of the agent’s trading performance during training

abstract tune(steps_per_train, steps_per_test, step_cb)[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.

  • step_cb (optional) – A callback function for monitoring progress of the tuning process. step_cb(pd.DataFrame) -> bool: A history of the agent’s trading performance is passed on each iteration. If the callback returns True, the training process will stop early.

Return type

pandas.DataFrame

Returns

A history of the agent’s trading performance during tuning