tensortrade.env.utils.feed_controller module

class tensortrade.env.utils.feed_controller.FeedController(feed: DataFeed, portfolio: Portfolio)[source]

Bases: Observable, TimeIndexed

This class is responsible for controlling the global feed in a TradingEnv.

The FeedController prepares the feed on initialization and provides access to the features, metadata and portfolio data. It has to be reset when the environment is reset and for new data next() has to be executed.

Note

The feed need to be a group of streams compiled together to a DataFeed. It should consists of:
  • features (Group): The features shown to the environment as observation for learning. This data should be normalized and prepared for the environment. If it’s missing a ValueError is raised.

  • meta (Group): The metadata used by the components, like plotters or plotters. This contains data like raw ohlcv data. It can be omitted but this will display a warning.

Parameters:
  • feed (DataFeed) – The feed to use.

  • portfolio (Portfolio) – The portfolio to fetch data from.

static create_portfolio_streams(portfolio: Portfolio) List[Stream[float]][source]

Creates a list of streams to describe a Portfolio.

Parameters:

portfolio (Portfolio) – The portfolio to create the streams for.

Returns:

A list of streams to describe a Portfolio.

Return type:

List[Stream[float]]

static create_wallet_source(wallet: Wallet, include_worth: bool = True) List[Stream[float]][source]

Creates a list of streams to describe a Wallet.

Parameters:
  • wallet (Wallet) – The wallet to create the streams for.

  • include_worth (bool) – Whether to include the worth of the wallet.

Returns:

A list of streams to describe a Wallet.

Return type:

List[Stream[float]]

property features_len: int

Gets the number of available features for training the model.

Returns:

The number of features.

Return type:

int

property features_size: int

Gets the number of features per state.

Returns:

The number of features per state.

Return type:

int

has_next() bool[source]

Checks if there is more data available.

Returns:

Whether there is new data available.

Return type:

bool

property meta_history: DataFrame

Gets the metadata history of this episode.

Returns:

The metadata history.

Return type:

DataFrame

next() None[source]

Get next data.

reset(random_start: int = 0) None[source]

Resets the feed and gets first data

property state: State

Gets the state at this point in time.

Returns:

The state.

Return type:

State

class tensortrade.env.utils.feed_controller.State(features: Dict[str, Any], meta: Dict[str, Any] | None, portfolio: Dict[str, Any], step: int)[source]

Bases: object

The actual state of the environment.

Parameters:
  • features (Dict[str, Any]) – The features at this point in time.

  • meta (Dict[str, Any]) – The metadata at this point in time. Could be None.

  • meta – The portfolio data at this point in time.

features: Dict[str, Any]
meta: Dict[str, Any] | None
portfolio: Dict[str, Any]
step: int