BacktestCryptoPosition

class qf_lib.backtesting.portfolio.backtest_crypto_position.BacktestCryptoPosition(ticker: qf_lib.common.tickers.tickers.Ticker)[source]

Bases: qf_lib.backtesting.portfolio.backtest_position.BacktestPosition

Methods

market_value()

It tells us what is the Market Value of the position.

total_exposure()

It tells us what is the total exposure of the position to the market in currency units

transact_transaction(transaction)

Update the state of a Position by using the Transaction containing information about datetime, price, quantity and commission.

market_value() → float[source]

It tells us what is the Market Value of the position.

For cash securities (Equities, Bonds, ETFs, etc)

It represents the value of the position (quantity * price) which is equal to the amount we could receive when we close the position

For margin securities (Futures, Options)

It represents the P&L of the position. So right after we buy a future contract its market_value is 0. It also represents the cash we could receive when we liquidate the position

Different behaviour comes form the fact that when we buy cash security we need to spend cash

(cash is removed from the portfolio)

However, when we buy a margin instrument (for example future contract) our cash is intact,

we only secure the margin which is not deducted from the cash we have.

total_exposure() → float[source]

It tells us what is the total exposure of the position to the market in currency units

For cash securities (Equities, Bonds, ETFs, etc)

It represents the value of the position (quantity * price)

For margin securities (Futures, Options)

It represents Notional of the position (quantity * price * contract size)

transact_transaction(transaction: qf_lib.backtesting.portfolio.transaction.Transaction) → float[source]

Update the state of a Position by using the Transaction containing information about datetime, price, quantity and commission.

Returns

  • transaction cost

  • For BUY transaction (how much we paid for the transaction including commission (it will be a negative number))

  • For SELL transaction (how much we received for selling shares including commission) – (it will be a positive number)