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).
- returns
one_over_n_weights
(tickers)Calculates the one-over-n weights for given tickers.
-
classmethod
constant_weights
(assets_rets_df: qf_lib.containers.dataframe.simple_returns_dataframe.SimpleReturnsDataFrame, weights: qf_lib.containers.series.qf_series.QFSeries) → Tuple[qf_lib.containers.series.simple_returns_series.SimpleReturnsSeries, qf_lib.containers.dataframe.qf_dataframe.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: qf_lib.containers.dataframe.simple_returns_dataframe.SimpleReturnsDataFrame, allocations_df: qf_lib.containers.dataframe.qf_dataframe.QFDataFrame) → qf_lib.containers.series.simple_returns_series.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: qf_lib.containers.dataframe.simple_returns_dataframe.SimpleReturnsDataFrame, weights: qf_lib.containers.series.qf_series.QFSeries) → Tuple[qf_lib.containers.series.simple_returns_series.SimpleReturnsSeries, qf_lib.containers.dataframe.qf_dataframe.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]
-
abstract
get_weights
() → qf_lib.containers.series.qf_series.QFSeries[source]¶ - Returns
- Return type
a series indexed with names of assets containing weights (one for each asset)
-
classmethod
one_over_n_weights
(tickers: Sequence[qf_lib.common.tickers.tickers.Ticker]) → qf_lib.containers.series.qf_series.QFSeries[source]¶ Calculates the one-over-n weights for given tickers.