Sensitivity of Portfolio’s CVaR to Shocks

perfana.monte_carlo.sensitivity.sensitivity_cvar_m(data, weights, shock=0.05, alpha=0.95, rebalance=True, invert=True, names=None, leveraged=False, distribute=True)[source]

Calculates the sensitivity of a shock to the CVaR of the portfolio

Notes

When given a positive shock and a “proportionate” distribution strategy, each asset class is given an additional amount by removing from the other asset classes proportionately. For example, given a portfolio with weights [0.1, 0.2, 0.3, 0.4], a shock of 5% to the first asset in the portfolio will result in weights [0.15, 0.19, 0.28, 0.38]. A negative shock works by removing from the asset class and adding to the other asset classes proportionately.

If the distribution strategy is set to False, the asset class’ weight is increased without removing from the other asset classes. Thus the sum of the portfolio weights will not equal 1.

By default, the portfolio is not leveraged. This means that the asset class be shorted (negative shock) to go below 0 and levered (positive shock) to go above 1. The asset class weight is thus capped between 0 and 1 by default. If the leverage option is set to True, then this value is no longer capped.

Parameters
  • data (ndarray) – Monte carlo simulation data. This must be 3 dimensional with the axis representing time, trial and asset respectively.

  • weights (array_like) – Weights of the portfolio. This must be 1 dimensional and must match the dimension of the data’s last axis.

  • shock (float) – The amount to shock each asset class by. A positive number represents adding to the asset class by proportionately removing from the other asset class. A negative number represents removing from the asset class and adding to the other asset class proportionately.

  • alpha (float) – Confidence level for calculation.

  • invert (bool) – Whether to invert the confidence interval level

  • rebalance (bool) – If True, portfolio is assumed to be rebalanced at every step.

  • names (list of str) – Asset class names

  • leveraged (bool) – If True, asset weights are allowed to go below 0 and above 1. This represents that the asset class can be shorted or levered.

  • distribute (bool) – If True, asset value changes are distributed proportionately to all other asset classes. See Notes for more information.

Returns

A series with asset names as the index and CVaR as its value

Return type

Series

Examples

>>> from perfana.datasets import load_cube
>>> from perfana.monte_carlo import sensitivity_cvar_m
>>> data = load_cube()[..., :7]
>>> weights = [0.25, 0.18, 0.13, 0.11, 0.24, 0.05, 0.04]
>>> freq = 'quarterly'
>>> shock = 0.05  # 5% absolute shock
>>> sensitivity_cvar_m(data, weights, shock)
Asset_1   -0.485220
Asset_2   -0.542988
Asset_3   -0.492411
Asset_4   -0.478581
Asset_5   -0.459786
Asset_6   -0.467798
Asset_7   -0.468692
Name: cvar, dtype: float64