Portfolio

class qf_lib.backtesting.portfolio.portfolio.Portfolio(data_handler: DataHandler, initial_cash: float, timer: Timer)[source]

Bases: object

Attributes:

current_cash

Represents the free cash in the portfolio.

gross_exposure_of_positions

Equals the sum of the absolute value of all positions except cash.

net_liquidation

Cash value includes futures P&L + stock value + securities options value + bond value + fund value.

open_positions_dict

Represents all open positions at a certain moment.

Methods:

leverage_series()

Leverage = GrossPositionValue / NetLiquidation

portfolio_eod_series()

Returns a timeseries of value of the portfolio expressed in currency units

positions_history()

Returns a QFDataFrame containing summary of the positions in the portfolio for each day.

transact_transaction(transaction)

Adjusts positions to account for a transaction.

update([record])

Updates the value of all positions that are currently open by getting the most recent price.

current_cash

Represents the free cash in the portfolio. Part of the cash might be use for margin.

gross_exposure_of_positions

Equals the sum of the absolute value of all positions except cash.

leverage_series() QFSeries[source]

Leverage = GrossPositionValue / NetLiquidation

net_liquidation

Cash value includes futures P&L + stock value + securities options value + bond value + fund value.

open_positions_dict

Represents all open positions at a certain moment.

portfolio_eod_series() PricesSeries[source]

Returns a timeseries of value of the portfolio expressed in currency units

positions_history() QFDataFrame[source]

Returns a QFDataFrame containing summary of the positions in the portfolio for each day.

transact_transaction(transaction: Transaction)[source]

Adjusts positions to account for a transaction. Handles any new position or modification to a current position

update(record=False)[source]

Updates the value of all positions that are currently open by getting the most recent price. The function is called at the end of the day (after market close) and after each executed transaction. If the flag record is set to True, it records the current assets values and the portfolio value (this is performed once per day, after the market close).