fynance.features.metrics.annual_return¶
-
fynance.features.metrics.
annual_return
(X, period=252, axis=0, dtype=None, ddof=0)¶ 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: - X : np.ndarray[dtype, ndim=1 or 2]
Time-series of price, performance or index.
- period : int, 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.
- dtype : np.dtype, optional
The type of the output array. If dtype is not given, infer the data type from X input.
- ddof : int, optional
Means Delta Degrees of Freedom, the divisor used in calculations is
T - ddof
, whereT
represents 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
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
[1] https://en.wikipedia.org/wiki/Rate_of_return#Annualisation 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])