Portfolio
- class qf_lib.portfolio_construction.portfolio_models.portfolio.Portfolio[source]
Bases:
object
Methods:
constant_weights
(assets_rets_df, weights)Calculates the time series of portfolio returns (given the weights of portfolio's assets).
different_allocations_tms
(assets_rets_df, ...)Calculates the time series of portfolio returns given the allocations on each date.
drifting_weights
(assets_rets_df, weights)Calculates the time series of portfolio returns (given the initial weights of portfolio's assets).
- rtype:
a series indexed with names of assets containing weights (one for each asset).
one_over_n_weights
(tickers)Calculates the one-over-n weights for given tickers.
- classmethod constant_weights(assets_rets_df: SimpleReturnsDataFrame, weights: QFSeries) Tuple[SimpleReturnsSeries, QFDataFrame] [source]
Calculates the time series of portfolio returns (given the weights of portfolio’s assets). Weights of assets are assumed to be the same all the time (there is a rebalancing on each time tick, e.g. every day if the series has a daily frequency).
The method also calculates the allocation matrix. However since the weights are constant, so are the allocations.
- Parameters:
assets_rets_df – simple returns of assets which create the portfolio
weights – weights of assets creating the portfolio
- Returns:
timeseries of portfolio’s returns, dataframe indexed with dates and showing allocations in time (one column per asset)
- Return type:
Tuple[SimpleReturnsSeries, QFDataFrame]
- classmethod different_allocations_tms(assets_rets_df: SimpleReturnsDataFrame, allocations_df: QFDataFrame) SimpleReturnsSeries [source]
Calculates the time series of portfolio returns given the allocations on each date. The portfolio returns are calculated by multiplying returns of assets by corresponding allocations’ values.
- Parameters:
assets_rets_df – simple returns of assets which create the portfolio
allocations_df – dataframe indexed with dates, showing allocations in time (one column per asset)
- Returns:
timeseries of portfolio’s returns
- Return type:
- classmethod drifting_weights(assets_rets_df: SimpleReturnsDataFrame, weights: QFSeries) Tuple[SimpleReturnsSeries, QFDataFrame] [source]
Calculates the time series of portfolio returns (given the initial weights of portfolio’s assets). Weights of assets change over time because there is no rebalancing.
The method also calculates the allocation matrix which shows what portfolio consists of on each date.
- Parameters:
assets_rets_df – simple returns of assets which create the portfolio
weights – weights of assets which create the portfolio
- Returns:
timeseries of portfolio’s returns, dataframe indexed with dates and showing allocations in time (one column per asset)
- Return type:
Tuple[SimpleReturnsSeries, QFDataFrame]