tensortrade.exchanges.instrument_exchange module

class tensortrade.exchanges.instrument_exchange.InstrumentExchange(base_instrument='USD', dtype=<class 'numpy.float16'>, feature_pipeline=None)[source]

Bases: object

An abstract instrument exchange for use within a trading environment.

__init__(base_instrument='USD', dtype=<class 'numpy.float16'>, feature_pipeline=None)[source]
Parameters
  • base_instrument (str) – The exchange symbol of the instrument to store/measure value in.

  • dtype (Union[type, str]) – A type or str corresponding to the dtype of the observation_space.

  • feature_pipeline (Optional[FeaturePipeline]) – A pipeline of feature transformations for transforming observations.

abstract property balance

The current balance of the base symbol on the exchange.

Return type

float

property base_instrument

The exchange symbol of the instrument to store/measure value in.

Return type

str

property base_precision

The floating point precision of the base instrument.

Return type

float

abstract current_price(symbol)[source]

The current price of an instrument on the exchange, denoted in the base instrument.

Parameters

symbol (str) – The exchange symbol of the instrument to get the price for.

Return type

float

Returns

The current price of the specified instrument, denoted in the base instrument.

property dtype

A type or str corresponding to the dtype of the observation_space.

Return type

Union[type, str]

abstract execute_trade(trade)[source]

Execute a trade on the exchange, accounting for slippage.

Parameters

trade (Trade) – The trade to execute.

Return type

Trade

Returns

The filled trade.

property feature_pipeline

A pipeline of feature transformations for transforming observations.

Return type

FeaturePipeline

abstract property generated_columns

The list of column names of the observation data frame generated by the exchange, before feature transformations.

Return type

List[str]

abstract property generated_space

The initial shape of the observations generated by the exchange, before feature transformations.

Return type

Space

abstract property has_next_observation

If False, the exchange’s data source has run out of observations.

Resetting the exchange may be necessary to continue generating observations.

Return type

bool

Returns

Whether or not the specified instrument has a next observation.

abstract property initial_balance

The initial balance of the base symbol on the exchange.

Return type

float

instrument_balance(symbol)[source]

The current balance of the specified symbol on the exchange, denoted in the base instrument.

Parameters

symbol (str) – The symbol to retrieve the balance of.

Return type

float

Returns

The balance of the specified exchange symbol, denoted in the base instrument.

property instrument_precision

The floating point precision of the instrument to be traded.

Return type

float

property net_worth

Calculate the net worth of the active account on the exchange.

Returns

The total portfolio value of the active account on the exchange.

Return type

float

next_observation()[source]

Generate the next observation from the exchange.

Return type

ndarray

Returns

The next multi-dimensional list of observations.

property observation_space

The final shape of the observations generated by the exchange, after feature transformations.

Return type

Space

abstract property performance

The performance of the active account on the exchange since the last reset.

Return type

DataFrame

abstract property portfolio

The current balance of each symbol on the exchange (non-positive balances excluded).

Return type

Dict[str, float]

property profit_loss_percent

Calculate the percentage change in net worth since the last reset.

Return type

float

Returns

The percentage change in net worth since the last reset.

abstract reset()[source]

Reset the feature pipeline, initial balance, trades, performance, and any other temporary stateful data.

abstract property trades

A list of trades made on the exchange since the last reset.

Return type

List[Trade]