tensortrade.environments.trading_environment module

class tensortrade.environments.trading_environment.TradingEnvironment(action_strategy, reward_strategy, exchange, **kwargs)[source]

Bases: gym.core.Env

A trading environment made for use with Gym-compatible reinforcement learning algorithms.

__init__(action_strategy, reward_strategy, exchange, **kwargs)[source]
Parameters
  • action_strategy (ActionStrategy) – The strategy for transforming an action into a TradeDefinition at each timestep.

  • reward_strategy (RewardStrategy) – The strategy for determining the reward at each timestep.

  • exchange (AssetExchange) – The AssetExchange that will be used to feed data from and execute trades within.

  • kwargs (optional) – Additional arguments for tuning the environment, logging, etc.

render(mode='none')[source]

Renders the environment.

reset()[source]

Resets the state of the environment and returns an initial observation.

Return type

pandas.DataFrame

Returns

observation – the initial observation.

step(action)[source]

Run one timestep within the environment based on the specified action.

Parameters

action – The trade action provided by the agent for this timestep.

Return type

Tuple[pandas.DataFrame, float, bool, dict]

Returns

observation (pandas.DataFrame) – Provided by the environment’s exchange, often OHLCV or tick trade history data points. reward (float): An amount corresponding to the advantage gained by the agent in this timestep. done (bool): If True, the environment is complete and should be restarted. info (dict): Any auxiliary, diagnostic, or debugging information to output.