tensortrade.oms.wallets.portfolio module

class tensortrade.oms.wallets.portfolio.Portfolio(base_instrument: tensortrade.oms.instruments.instrument.Instrument, wallets: List[WalletType] = None, order_listener: Optional[tensortrade.oms.orders.order_listener.OrderListener] = None, performance_listener: Callable[[collections.OrderedDict], None] = None)[source]

Bases: tensortrade.core.component.Component, tensortrade.core.base.TimedIdentifiable

A portfolio of wallets on exchanges.

Parameters:
  • base_instrument (Instrument) – The exchange instrument used to measure value and performance statistics.
  • wallets (List[WalletType]) – The wallets to be used in the portfolio.
  • order_listener (OrderListener) – The order listener to set for all orders executed by this portfolio.
  • performance_listener (Callable[[OrderedDict], None]) – The performance listener to send all portfolio updates to.
add(wallet: WalletType) → None[source]

Adds a wallet to the portfolio.

Parameters:wallet (WalletType) – The wallet to add to the portfolio.
balance(instrument: tensortrade.oms.instruments.instrument.Instrument) → tensortrade.oms.instruments.quantity.Quantity[source]

Gets the total balance of the portfolio in a specific instrument available for use.

Parameters:instrument (Instrument) – The instrument to compute the balance for.
Returns:Quantity – The balance of the instrument over all wallets.
balances

The current unlocked balance of each instrument over all wallets. (List[Quantity], read-only)

base_balance

The current balance of the base instrument over all wallets. (Quantity, read-only)

exchange_pairs

All the exchange pairs in the portfolio. (List[ExchangePair], read-only)

exchanges

All the exchanges in the portfolio. (List[Exchange], read-only)

get_wallet(exchange_id: str, instrument: tensortrade.oms.instruments.instrument.Instrument) → tensortrade.oms.wallets.wallet.Wallet[source]

Gets wallet by the exchange_id and instrument.

Parameters:
  • exchange_id (str) – The exchange id used to identify the wallet.
  • instrument (Instrument) – The instrument used to identify the wallet.
Returns:

Wallet – The wallet associated with exchange_id and instrument.

initial_balance

The initial balance of the base instrument over all wallets. (Quantity, read-only)

initial_net_worth

The initial net worth of the portfolio. (float, read-only)

ledger

The ledger that keeps track of transactions. (Ledger, read-only)

locked_balance(instrument: tensortrade.oms.instruments.instrument.Instrument) → tensortrade.oms.instruments.quantity.Quantity[source]

Gets the total balance a specific instrument locked in orders over the entire portfolio.

Parameters:instrument (Instrument) – The instrument to find locked balances for.
Returns:Quantity – The total locked balance of the instrument.
locked_balances

The current locked balance of each instrument over all wallets. (List[Quantity], read-only)

net_worth

The current net worth of the portfolio. (float, read-only)

on_next(data: dict) → None[source]

Updates the performance metrics.

Parameters:data (dict) – The data produced from the observer feed that is used to update the performance metrics.
performance

The performance of the portfolio since the last reset. (OrderedDict, read-only)

profit_loss

The percent loss in net worth since the last reset. (float, read-only)

registered_name = 'portfolio'
remove(wallet: tensortrade.oms.wallets.wallet.Wallet) → None[source]

Removes a wallet from the portfolio.

Parameters:wallet (Wallet) – The wallet to be removed.
remove_pair(exchange: tensortrade.oms.exchanges.exchange.Exchange, instrument: tensortrade.oms.instruments.instrument.Instrument) → None[source]

Removes a wallet from the portfolio by exchange and instrument.

Parameters:
  • exchange (Exchange) – The exchange of the wallet to be removed.
  • instrument (Instrument) – The instrument of the wallet to be removed.
reset() → None[source]

Resets the portfolio.

total_balance(instrument: tensortrade.oms.instruments.instrument.Instrument) → tensortrade.oms.instruments.quantity.Quantity[source]

Gets the total balance of a specific instrument over the portfolio, both available for use and locked in orders.

Parameters:instrument (Instrument) – The instrument to get total balance of.
Returns:Quantity – The total balance of instrument over the portfolio.
total_balances

The current total balance of each instrument over all wallets. (List[Quantity], read-only)

wallets

All the wallets in the portfolio. (List[Wallet], read-only)