SimulatedExchange

An exchange, in which the price history is based off the supplied data frame and trade execution is largely decided by the designated slippage model. If the data_frame parameter is not supplied upon initialization, it must be set before the exchange can be used within a trading environment.

The reason we create simulated exchanges is so we create more robust models quickly. We train using either sampled or fake information. Usually the data sets are stochastic in nature.

Class Parameters

  • base_instrument
    • The exchange symbol of the instrument to store/measure value in.
  • dtype
    • A type or str corresponding to the dtype of the observation_space.
  • feature_pipeline
    • A pipeline of feature transformations for transforming observations.
  • kwargs
    • Go through each of them here

Properties and Setters

  • base_instrument
    • The exchange symbol of the instrument to store/measure value in.
  • dtype
    • A type or str corresponding to the dtype of the observation_space.
  • feature_pipeline
    • A pipeline of feature transformations for transforming observations.
  • base_precision
    • The floating point precision of the base instrument.
  • instrument_precision
    • The floating point precision of the instrument to be traded.
  • initial_balance
    • The initial balance of the base symbol on the exchange.
  • balance
    • The current balance of the base symbol on the exchange.
  • portfolio
    • The current balance of each symbol on the exchange (non-positive balances excluded).
  • trades
    • A list of trades made on the exchange since the last reset.
  • performance
    • The performance of the active account on the exchange since the last reset.
  • generated_space
    • The initial shape of the observations generated by the exchange, before feature transformations.
  • generated_columns
    • The list of column names of the observation data frame generated by the exchange, before feature transformations.
  • observation_space
    • The final shape of the observations generated by the exchange, after feature transformations.
  • net_worth
    • Calculate the net worth of the active account on the exchange.
  • profit_loss_percent
    • Calculate the percentage change in net worth since the last reset.
  • 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.

Functions

Below are the functions that the SimulatedExchange uses to effectively operate.

Private

  • _create_observation_generator

Public

  • has_next_observation
    • Return the reward corresponding to the selected risk-adjusted return metric.
  • next_observation
    • Generate the next observation from the exchange.
  • instrument_balance
    • The current balance of the specified symbol on the exchange, denoted in the base instrument.
  • current_price
    • The current price of an instrument on the exchange, denoted in the base instrument.
  • execute_trade
    • Execute a trade on the exchange, accounting for slippage.
  • reset
    • Reset the feature pipeline, initial balance, trades, performance, and any other temporary stateful data.

Use Cases

import pandas as pd
from tensortrade.exchanges.simulated import SimulatedExchange

df = pd.read_csv('./data/btc_ohclv_1h.csv')
exchange = SimulatedExchange(data_frame=df, base_instrument='USD')

Use Cases

Working on it.