CVaR Attribution¶
-
perfana.monte_carlo.risk.
cvar_attr
(data, weights, alpha=0.95, rebalance=True, invert=True)[source]¶ Calculates the CVaR (Expected Shortfall) attribution for each asset class in the portfolio.
Notes
From a mathematical point of view, the alpha value (confidence level for calculation) should be taken at the negative extreme of the distribution. However, the default is set to ease the practitioner.
The return values are defined as follows:
- marginal
The absolute marginal contribution of the asset class towards the portfolio CVaR. It is essentially the percentage attribution multiplied by the portfolio CVaR.
- percentage
The percentage contribution of the asset class towards the portfolio CVaR. This number though named in percentage is actually in decimals. Thus 0.01 represents a 1% contribution.
- Parameters
data (
ndarray
) – Monte carlo simulation data. This must be 3 dimensional with the axis representing time, trial and asset respectively.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.alpha – Confidence level for calculation.
rebalance – If True, portfolio is assumed to be rebalanced at every step.
invert – Whether to invert the confidence interval level. See Notes.
- Returns
A named tuple of relative and absolute CVaR (expected shortfall) attribution respectively. The absolute attribution is the CVaR 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 cvar_attr >>> cube = load_cube()[..., :3] >>> weights = [0.33, 0.34, 0.33] >>> attr = cvar_attr(cube, weights, alpha=0.95) >>> attr.marginal array([-0.186001 , -0.35758411, -0.20281477]) >>> attr.percentage array([0.24919752, 0.47907847, 0.27172401]) >>> attr.marginal is attr[0] True >>> attr.percentage is attr[1] True