annual_return¶
Defined in fynance.features.metrics
- annual_return(X, period=252, axis=0, dtype=None, ddof=0)[source]
Compute 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).
- 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, whereTrepresents the number of elements in time axis. Default is 0.
- Returns:
- dtype or np.ndarray[dtype, ndim=1]
Values of compouned annual returns of each series.
See also
mdd,drawdown,sharpe,annual_volatility
Notes
Let T the number of timeframes in X’ series, the annual compouned returns is computed such that:
\[annualReturn = \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) >>> print(round(annual_return(X, period=12), 4)) 0.1664 >>> X = np.array([[100, 110], [80, 120], [160, 108]]).astype(np.float64) >>> annual_return(X, period=12, ddof=1) array([15.777216 , -0.10425081])