Drawdown Summary¶
-
perfana.core.risk.
drawdown_summary
(data, weights=None, geometric=True, rebalance=True, *, top=5)[source]¶ A summary of each drawdown instance. Output is ranked by depth of the drawdown.
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 matrixweights (
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.
top (
Optional
[int
]) – If None, returns all episodes. If specified, returns the top n episodes ranked by the depth of drawdown.
- Returns
A data frame summarizing each drawdown episode
- Return type
DataFrame
Examples
>>> from perfana.datasets import load_hist >>> from perfana.core import drawdown_summary >>> hist = load_hist().iloc[:, :7] >>> weights = [0.25, 0.18, 0.24, 0.05, 0.04, 0.13, 0.11] >>> drawdown_summary(hist, weights) Start Trough End Drawdown Length ToTrough Recovery 0 2007-11-30 2009-02-28 2014-02-28 -0.400798 76 16 60 1 2000-04-30 2003-03-31 2004-02-29 -0.203652 47 36 11 2 1990-01-31 1990-11-30 1991-05-31 -0.150328 17 11 6 3 1998-04-30 1998-10-31 1999-06-30 -0.149830 15 7 8 4 1994-02-28 1995-03-31 1996-01-31 -0.132766 24 14 10 >>> drawdown_summary(hist.iloc[:, 0]) Start Trough End Drawdown Length ToTrough Recovery 0 2007-11-30 2009-02-28 2014-05-31 -0.549134 79 16 63 1 2000-04-30 2003-03-31 2006-12-31 -0.474198 81 36 45 2 1990-01-31 1990-09-30 1994-01-31 -0.286489 49 9 40 3 1998-08-31 1998-09-30 1999-01-31 -0.148913 6 2 4 4 2018-10-31 2018-12-31 2019-03-31 -0.130014 6 3 3