Risk Performance Benchmark¶
-
perfana.monte_carlo.risk.
prob_loss
(data, weights, rebalance=True, terminal=False)[source]¶ Calculates the probability of the portfolio suffering a loss。
- 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.rebalance – If True, portfolio is assumed to be rebalanced at every step.
terminal – If True, this only compares the probability of a loss at the last stage. If False (default), the calculation will take into account if the portfolio was “ruined” and count it as a loss even though the terminal value is positive.
- Returns
A named tuple containing the probability of underperformance and loss
- Return type
float
Examples
>>> from perfana.datasets import load_cube >>> from perfana.monte_carlo import prob_loss >>> data = load_cube() >>> weights = [0.25, 0.18, 0.13, 0.11, 0.24, 0.05, 0.04] >>> prob_loss(data, weights) 0.198