Correlation Measure¶
-
perfana.core.relative.
correlation_measure
(portfolio, benchmark, duration='monthly', *, is_returns=False, date_as_index=True)[source]¶ Computes the correlation measure 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
- Parameters
portfolio (
Union
[DataFrame
,Iterable
[Union
[int
,float
]],ndarray
,Series
]) – The portfolio values vector or matrixbenchmark (
Union
[DataFrame
,Iterable
[Union
[int
,float
]],ndarray
,Series
]) – The benchmark values vector or matrixduration (
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 correlation measure 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 correlation measure 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 correlation_measure >>> etf = load_etf().dropna() >>> returns = etf.iloc[:, 1:] >>> benchmark = etf.iloc[:, 0] >>> correlation_measure(returns, benchmark, 'monthly').head() BND VTI VWO Date 2007-05-10 -0.384576 0.890783 0.846000 2007-05-11 -0.525299 0.911693 0.857288 2007-05-14 -0.482180 0.912002 0.855114 2007-05-15 -0.439073 0.913992 0.842561 2007-05-16 -0.487110 0.899859 0.837781