roll_annual_return

Defined in fynance.features.metrics

roll_annual_return(X, period=252, w=None, axis=0, dtype=None, ddof=0)[source]

Compute rolling compouned annual returns of each X’ series.

The annualised return [1] is the process of converting returns on a whole period to returns per year.

Parameters:
Xnp.ndarray[dtype, ndim=1 or 2]

Time-series of price, performance or index.

periodint, optional

Number of period per year, default is 252 (trading days per year).

wint, optional

Size of the lagged window of the rolling function, must be positive. If w is None or w=0, then w=X.shape[axis]. Default is None.

axis{0, 1}, optional

Axis along wich the computation is done. Default is 0.

dtypenp.dtype, optional

The type of the output array. If dtype is not given, infer the data type from X input.

ddofint, optional

Means Delta Degrees of Freedom, the divisor used in calculations is t - ddof, where t represents the number of elements in time axis. Default is 0.

Returns:
np.ndarray[dtype, ndim=1 or 2]

Values of rolling compouned annual returns of each series.

See also

mdd, drawdown, sharpe, annual_volatility

Notes

The rolling annual compouned returns is computed such that \(\forall t \in [1: T]\):

\[annualReturn_t = \frac{X_t}{X_1}^{\frac{period}{t}} - 1\]

References

Examples

Assume series of monthly prices:

>>> X = np.array([100, 110, 80, 120, 160, 108]).astype(np.float64)
>>> roll_annual_return(X, period=12)
array([ 0.        ,  0.771561  , -0.5904    ,  0.728     ,  2.08949828,
        0.1664    ])
>>> X = np.array([[100, 101], [80, 81], [110, 108]]).astype(np.float64)
>>> roll_annual_return(X, period=12, axis=1)
array([[ 0.        ,  0.06152015],
       [ 0.        ,  0.07738318],
       [ 0.        , -0.10425081]])