Returns Attribution¶
-
perfana.monte_carlo.returns.
returns_attr
(data, weights, freq, geometric=True, rebalance=True)[source]¶ Derives the returns attribution given a data cube and weights.
Notes
The return values are defined as follows:
- marginal
The absolute marginal contribution of the asset class towards the portfolio returns. It is essentially the percentage attribution multiplied by the portfolio returns.
- percentage
The percentage contribution of the asset class towards the portfolio returns. This number though named in percentage is actually in decimals. Thus 0.01 represents a 1% contribution.
- 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
]) – 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.
- Returns
A named tuple of marginal and percentage returns attribution respectively. The marginal attribution is the returns of the simulated data over time multiplied by the percentage attribution.
- Return type
Attribution
Examples
>>> from perfana.datasets import load_cube >>> from perfana.monte_carlo import returns_attr >>> cube = load_cube()[..., :3] >>> weights = [0.33, 0.34, 0.33] >>> freq = "quarterly" >>> attr = returns_attr(cube, weights, freq) >>> attr.marginal array([0.00996204, 0.00733369, 0.00963802]) >>> attr.percentage array([0.36987203, 0.27228623, 0.35784174]) >>> attr.marginal is attr[0] True >>> attr.percentage is attr[1] True