tensortrade.env.default.observers module

class tensortrade.env.default.observers.IntradayObserver(portfolio: Portfolio, feed: DataFeed = None, renderer_feed: DataFeed = None, stop_time: datetime.time = datetime.time(16, 0), window_size: int = 1, min_periods: int = None, randomize: bool = False, **kwargs)[source]

Bases: tensortrade.env.generic.components.observer.Observer

The IntradayObserver observer that is compatible with the other default components. :param portfolio: The portfolio to be used to create the internal data feed mechanism. :type portfolio: Portfolio :param feed: The feed to be used to collect observations to the observation window. :type feed: DataFeed :param renderer_feed: The feed to be used for giving information to the renderer. :type renderer_feed: DataFeed :param stop_time: The time at which the episode will stop. :type stop_time: datetime.time :param window_size: The size of the observation window. :type window_size: int :param min_periods: The amount of steps needed to warmup the feed. :type min_periods: int :param randomize: Whether or not to select a random episode when reset. :type randomize: bool :param **kwargs: Additional keyword arguments for observer creation. :type **kwargs: keyword arguments

feed

The master feed in charge of streaming the internal, external, and renderer data feeds.

Type:DataFeed
stop_time

The time at which the episode will stop.

Type:datetime.time
window_size

The size of the observation window.

Type:int
min_periods

The amount of steps needed to warmup the feed.

Type:int
randomize

Whether or not a random episode is selected when reset.

Type:bool
history

The observation history.

Type:ObservationHistory
renderer_history

The history of the renderer data feed.

Type:List[dict]
has_next() → bool[source]

Checks if there is another observation to be generated. :returns: bool – Whether there is another observation to be generated.

observation_space

The observation space of the TradingEnv. (Space, read-only)

observe(env: TradingEnv) → numpy.array[source]

Observes the environment. As a consequence of observing the env, a new observation is generated from the feed and stored in the observation history. :returns: np.array – The current observation of the environment.

reset() → None[source]

Resets the observer

warmup() → None[source]

Warms up the data feed.

class tensortrade.env.default.observers.ObservationHistory(window_size: int)[source]

Bases: object

Stores observations from a given episode of the environment.

Parameters:window_size (int) – The amount of observations to keep stored before discarding them.
window_size

The amount of observations to keep stored before discarding them.

Type:int
rows

The rows of observations that are used as the environment observation at each step of an episode.

Type:pd.DataFrame
observe() → numpy.array[source]

Gets the observation at a given step in an episode

Returns:np.array – The current observation of the environment.
push(row: dict) → None[source]

Stores an observation.

Parameters:row (dict) – The new observation to store.
reset() → None[source]

Resets the observation history

class tensortrade.env.default.observers.TensorTradeObserver(portfolio: Portfolio, feed: DataFeed = None, renderer_feed: DataFeed = None, window_size: int = 1, min_periods: int = None, **kwargs)[source]

Bases: tensortrade.env.generic.components.observer.Observer

The TensorTrade observer that is compatible with the other default components.

Parameters:
  • portfolio (Portfolio) – The portfolio to be used to create the internal data feed mechanism.
  • feed (DataFeed) – The feed to be used to collect observations to the observation window.
  • renderer_feed (DataFeed) – The feed to be used for giving information to the renderer.
  • window_size (int) – The size of the observation window.
  • min_periods (int) – The amount of steps needed to warmup the feed.
  • **kwargs (keyword arguments) – Additional keyword arguments for observer creation.
feed

The master feed in charge of streaming the internal, external, and renderer data feeds.

Type:DataFeed
window_size

The size of the observation window.

Type:int
min_periods

The amount of steps needed to warmup the feed.

Type:int
history

The observation history.

Type:ObservationHistory
renderer_history

The history of the renderer data feed.

Type:List[dict]
has_next() → bool[source]

Checks if there is another observation to be generated.

Returns:bool – Whether there is another observation to be generated.
observation_space

The observation space of the TradingEnv. (Space, read-only)

observe(env: TradingEnv) → numpy.array[source]

Observes the environment.

As a consequence of observing the env, a new observation is generated from the feed and stored in the observation history.

Returns:np.array – The current observation of the environment.
reset() → None[source]

Resets the observer

warmup() → None[source]

Warms up the data feed.