Portfolio CVaR¶
-
perfana.monte_carlo.risk.
cvar_m
(data, weights, alpha=0.95, rebalance=True, invert=True)[source]¶ Calculates the Conditional Value at Risk (Expected Shortfall) of 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.
- 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
CVaR (Expected Shortfall) of the portfolio
- Return type
float
Examples
>>> from perfana.datasets import load_cube >>> from perfana.monte_carlo import cvar_m >>> cube = load_cube()[..., :3] >>> weights = [0.33, 0.34, 0.33] >>> cvar_m(cube, weights) -0.7463998716846179