Previous topic

fynance.features.metrics.roll_calmar

Next topic

fynance.features.metrics.roll_mad

fynance.features.metrics.roll_drawdown

fynance.features.metrics.roll_drawdown(X, w=None, raw=False, axis=0, dtype=None)

Measures the rolling drawdown of each X’ series.

Function to compute 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 of prices, performances or index. Must be positive values.

w : int, 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.

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.ndarray[dtype, ndim=1 or 2]

Series of drawdown for each series.

See also

mdd, calmar, sharpe, roll_mdd

Notes

Let DD^w the drawdown vector with a lagged window of size w:

\[\begin{split}DD^w_t =\begin{cases} max(X_{t - w + 1:t}) - X_t \text{, if raw=True} \\ 1 - \frac{X_t}{max(X_{t - w + 1:t})} \text{, otherwise} \\ \end{cases}\end{split}\]

References

[5]https://en.wikipedia.org/wiki/Drawdown_(economics)

Examples

>>> X = np.array([70, 100, 80, 120, 160, 80]).astype(np.float64)
>>> roll_drawdown(X)
array([0. , 0. , 0.2, 0. , 0. , 0.5])
>>> roll_drawdown(X.reshape([6, 1])).T
array([[0. , 0. , 0.2, 0. , 0. , 0.5]])
>>> roll_drawdown(X, raw=True)
array([ 0.,  0., 20.,  0.,  0., 80.])
>>> X = np.array([100, 80, 70, 75, 110, 80]).astype(np.float64)
>>> roll_drawdown(X, raw=True, w=3)
array([ 0., 20., 30.,  5.,  0., 30.])