Returns Distribution

perfana.monte_carlo.returns.returns_distribution(data, weights, freq=None, annualize=True, geometric=True, rebalance=True)[source]

Calculates the returns distribution of the simulation 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.

  • freq (Union[str, int, None]) – 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. If annualize is False, freq can be ignored.

  • annualize – If true, the returns distribution values are annualized

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

Returns

A vector of the distribution of returns

Return type

Array

Examples

>>> from perfana.datasets import load_cube
>>> from perfana.monte_carlo import returns_distribution
>>> cube = load_cube()[..., :3]
>>> weights = [0.33, 0.34, 0.33]
>>> freq = "quarterly"
>>> returns_distribution(cube, weights, freq).shape
(1000,)