Relative Price Index

perfana.core.relative.relative_price_index(portfolio, benchmark, duration='monthly', *, is_returns=False, date_as_index=True)[source]

Computes the relative price index through time. The data is assumed to be daily. If the benchmark is a single series, a single TimeSeriesData will be returned. Otherwise, a dictionary of TimeSeries will be returned where the keys are each individual benchmark

Notes

The relative price index at a particular time \(t\) for an asset \(a\) against its benchmark \(b\) is given by

\[RP_{a, t} = r_{a, t - d} - r_{b, t - d}\]

where d is the duration. For example, if the duration is ‘monthly’, \(d\) will be 22 days.

Parameters
  • portfolio (Union[DataFrame, Iterable[Union[int, float]], ndarray, Series]) – The portfolio values vector or matrix

  • benchmark (Union[DataFrame, Iterable[Union[int, float]], ndarray, Series]) – The benchmark values vector or matrix

  • duration (Union[str, int]) – Duration to calculate the relative price index with. Either a string or positive integer value can be specified. Supported string values are ‘day’, ‘week’, ‘month’, ‘quarter’, ‘semi-annual’ and ‘year’

  • is_returns – Set this to true if the portfolio and benchmark values are in “returns” instead of raw values (i.e. prices or raw index value)

  • date_as_index – If true, returns the date as the dataframe’s index. Otherwise, the date is placed as a column in the dataframe

Returns

A DataFrame of the relative price index between the assets in the portfolio against the benchmark If multiple series are included in the benchmark, returns a dictionary where the keys are the benchmarks’ name and the values are the relative price index of the portfolio against that particular benchmark

Return type

TimeSeriesData or dict of TimeSeriesData

Examples

>>> from perfana.datasets import load_etf
>>> from perfana.core import relative_price_index
>>> etf = load_etf().dropna()
>>> returns = etf.iloc[:, 1:]
>>> benchmark = etf.iloc[:, 0]
>>> relative_price_index(returns, benchmark, 'monthly').head()
                 BND       VTI       VWO
Date
2007-05-10 -0.016000  0.009433  0.000458
2007-05-11 -0.031772  0.008626  0.013009
2007-05-14 -0.016945  0.014056  0.008658
2007-05-15 -0.002772  0.020824  0.018758
2007-05-16  0.002791  0.025402  0.028448