fynance.features.metrics.roll_mdd¶
-
fynance.features.metrics.
roll_mdd
(X, w=None, raw=False, axis=0, dtype=None)¶ Compute the rolling maximum drawdown for each X’ series.
Where drawdown is the measure of the decline from a historical peak in some variable [5] (typically the cumulative profit or total open equity of a financial trading strategy).
Parameters: - X : np.ndarray[dtype, ndim=1 or 2]
Time series (price, performance or index).
- w : int, optional
Size of the lagged window of the rolling function, must be positive. If
w is None
orw=0
, thenw=X.shape[axis]
. Default is None.- raw : bool, optional
- If True then compute the raw drawdown.
- Else (default) compute the drawdown in percentage.
- 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.
Returns: - np.ndrray[dtype, ndim=1 or 2]
Series of rolling maximum drawdown for each series.
See also
References
[5] https://www.investopedia.com/terms/m/maximum-drawdown-mdd.asp Examples
>>> X = np.array([70, 100, 80, 120, 160, 80]) >>> roll_mdd(X, dtype=np.float64) array([0. , 0. , 0.2, 0.2, 0.2, 0.5]) >>> roll_mdd(X, w=3, dtype=np.float64) array([0. , 0. , 0.2, 0.2, 0. , 0.5]) >>> X = np.array([100, 80, 70, 75, 110, 80]).astype(np.float64) >>> roll_mdd(X, raw=True, w=3, dtype=np.float64) array([ 0., 20., 30., 10., 0., 30.])