Drawdown

perfana.core.risk.drawdown(data, weights=None, geometric=True, rebalance=True)[source]

Calculates the drawdown at each time instance.

If data is DataFrame-like, weights must be specified. If data is Series-like, weights can be left empty.

Parameters
  • data (Union[DataFrame, Iterable[Union[int, float]], ndarray, Series]) – The assets returns vector or matrix

  • weights (Union[Iterable[Union[int, float]], ndarray, Series, None]) – Weights of the portfolio. This must be 1 dimensional and must match the dimension of the data’s last axis.

  • geometric – If True, calculates the geometric mean, otherwise, calculates the arithmetic mean.

  • rebalance – If True, portfolio is assumed to be rebalanced at every step.

Returns

Drawdown at each time instance

Return type

Series

Examples

>>> from perfana.datasets import load_hist
>>> from perfana.core import drawdown
>>> hist = load_hist().iloc[:, :7]
>>> weights = [0.25, 0.18, 0.24, 0.05, 0.04, 0.13, 0.11]
>>> drawdown(hist, weights).min()
-0.4007984968456346
>>> drawdown(hist.iloc[:, 0]).min()
-0.5491340502573534
import matplotlib.pyplot as plt

from perfana.core import drawdown
from perfana.datasets import load_hist

data = load_hist().iloc[:, :7]
weights = [0.25, 0.18, 0.13, 0.11, 0.24, 0.05, 0.04]

dd = drawdown(data, weights)
plt.plot(dd.index, dd)
plt.title("Drawdown")
plt.xlabel("Time")
plt.ylabel("Drawdown Depth")
plt.show()

(Source code)