Volatility Attribution

perfana.monte_carlo.risk.vol_attr(cov_or_data, weights, freq)[source]

Derives the volatility attribution given a data cube and weights.

Notes

The return values are defined as follows:

marginal

The absolute marginal contribution of the asset class towards the portfolio volatility. It is essentially the percentage attribution multiplied by the portfolio volatility.

percentage

The percentage contribution of the asset class towards the portfolio volatility. This number though named in percentage is actually in decimals. Thus 0.01 represents a 1% contribution.

Parameters
  • cov_or_data (ndarray) – Covariance matrix or simulated returns data cube.

  • weights (Union[Iterable[Union[int, float]], ndarray, Series]) – Weights of the portfolio. This must be 1 dimensional and must match the dimension of the data’s last axis.

  • freq (Union[str, int]) – Frequency of the data. Can either be a string (‘week’, ‘month’, ‘quarter’, ‘semi-annual’, ‘year’) or an integer specifying the number of units per year. Week: 52, Month: 12, Quarter: 4, Semi-annual: 6, Year: 1.

Returns

A named tuple of relative and absolute volatility attribution respectively. The absolute attribution is the volatility of the simulated data over time multiplied by the percentage attribution.

Return type

Attribution

Examples

>>> from perfana.datasets import load_cube
>>> from perfana.monte_carlo import vol_attr
>>> data = load_cube()[..., :3]  # first 3 asset classes only
>>> weights = [0.33, 0.34, 0.33]
>>> freq = 'quarterly'
>>> attr = vol_attr(data, weights, freq)
>>> attr.marginal.round(4)
array([0.2352, 0.5006, 0.2643])
>>> attr.percentage.round(4)
array([0.0445, 0.0947, 0.05  ])
>>> attr.marginal is attr[0]
True
>>> attr.percentage is attr[1]
True