Annualized Quantile Returns

perfana.monte_carlo.returns.annualized_quantile_returns_m(data, weights, quantile, freq, geometric=True, rebalance=True, interpolation='midpoint')[source]

Compute the q-th quantile of the returns in the simulated data cube.

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.

  • quantile (Union[float, Iterable[float]]) – Quantile or sequence of quantiles to compute, which must be between 0 and 1 inclusive

  • 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.

  • geometric (bool) – If True, calculates the geometric mean, otherwise, calculates the arithmetic mean.

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

  • interpolation

    This optional parameter specifies the interpolation method to use when the desired quantile lies between two data points i < j:

    • linear: i + (j - i) * fraction, where fraction is the fractional part of the index surrounded by i and j.

    • lower: i.

    • higher: j.

    • nearest: i or j, whichever is nearest.

    • midpoint: (i + j) / 2.

Returns

The returns of the portfolio relative to the benchmark at the specified quantile

Return type

float

Examples

>>> from perfana.datasets import load_cube
>>> from perfana.monte_carlo import annualized_quantile_returns_m
>>> cube = load_cube()[..., :7]
>>> weights = [0.25, 0.18, 0.13, 0.11, 0.24, 0.05, 0.04]
>>> freq = "quarterly"
>>> q = 0.25
>>> annualized_quantile_returns_m(cube, weights, q, freq)
0.005468353416130167
>>> q = [0.25, 0.75]
>>> annualized_quantile_returns_m(cube, weights, q, freq)
array([0.00546835, 0.03845033])