Portfolio
- class qf_lib.backtesting.portfolio.portfolio.Portfolio(data_provider: AbstractPriceDataProvider, initial_cash: float, currency: Optional[str] = None)[source]
Bases:
objectAttributes:
Represents the free cash in the portfolio.
Equals the sum of the absolute value of all positions except cash.
Cash value includes futures P&L + stock value + securities options value + bond value + fund value.
Represents all open positions at a certain moment.
Methods:
Leverage = GrossPositionValue / NetLiquidation
net_liquidation_in_currency([currency])Converts the current net liquidation from the portfolio currency into the specified currency
Returns a timeseries of value of the portfolio expressed in currency units
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.
- net_liquidation
Cash value includes futures P&L + stock value + securities options value + bond value + fund value.
- net_liquidation_in_currency(currency: str = None) float[source]
Converts the current net liquidation from the portfolio currency into the specified currency
- 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).