tensortrade.oms.wallets.portfolio module

class tensortrade.oms.wallets.portfolio.Portfolio(*args, **kwargs)[source]

Bases: Component, 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: Instrument) 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.

property balances: List[Quantity]

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

property base_balance: Quantity

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

property clock: Clock

Gets the clock associated with the object.

Returns:

Clock – The clock associated with the object.

property exchange_pairs: List[ExchangePair]

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

property exchanges: List[Exchange]

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

get_wallet(exchange_id: str, instrument: Instrument) 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.

property initial_balance: Quantity

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

property initial_net_worth: float

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

property ledger: Ledger

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

locked_balance(instrument: Instrument) 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.

property locked_balances: List[Quantity]

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

property net_worth: float

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

on_next(data: State) None[source]

Updates the performance metrics.

Parameters:

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

property performance: OrderedDict

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

property profit_loss: float

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

registered_name = 'portfolio'
remove(wallet: Wallet) None[source]

Removes a wallet from the portfolio.

Parameters:

wallet (Wallet) – The wallet to be removed.

remove_pair(exchange: Exchange, 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: Instrument) 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.

property total_balances: List[Quantity]

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

property wallets: List[Wallet]

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