Previous topic

fynance.features.metrics.diversified_ratio

fynance.features.metrics.drawdown¶

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

Measures the 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. 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. np.ndarray[dtype, ndim=1 or 2] Series of drawdown for each series.

mdd, calmar, sharpe, roll_mdd

Notes

Let DD the drawdown vector, $$\forall t \in [1:T]$$:

$\begin{split}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}\end{split}$

References

Examples

>>> X = np.array([70, 100, 80, 120, 160, 80]).astype(np.float64)
>>> drawdown(X)
array([0. , 0. , 0.2, 0. , 0. , 0.5])
>>> drawdown(X.reshape([6, 1])).T
array([[0. , 0. , 0.2, 0. , 0. , 0.5]])
>>> drawdown(X, raw=True)
array([ 0.,  0., 20.,  0.,  0., 80.])