Previous topic

fynance.features.metrics.mad

Next topic

fynance.features.metrics.perf_index

fynance.features.metrics.mdd

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

Compute the maximum drawdown for each X’ series.

Drawdown (:func:~`fynance.features.metrics.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[np.dtype, ndim=1 or 2]

Time-series of prices, performances or index.

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

Value of Maximum DrawDown for each series.

Notes

Let DD the drawdown vector:

\[MDD = max(DD_{1:T})\]

Where, \(DD_t = \begin{cases}max(X_{1:t}) - X_t \text{, if raw=True} \\ 1 - \frac{X_t}{max(X_{1:t})} \text{, otherwise} \\ \end{cases}\), \(\forall t \in [1:T]\).

References

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

Examples

>>> X = np.array([70, 100, 80, 120, 160, 80]).astype(np.float64)
>>> mdd(X)
0.5
>>> mdd(X.reshape([6, 1]))
array([0.5])