diff --git a/pyfolio/bayesian.py b/pyfolio/bayesian.py index 549d8f03..23a25d73 100644 --- a/pyfolio/bayesian.py +++ b/pyfolio/bayesian.py @@ -106,11 +106,7 @@ def model_returns_t_alpha_beta(data, bmark, samples=2000): def model_returns_normal(data, samples=500): - """Run Bayesian model assuming returns are Student-T distributed. - - Compared with the normal model, this model assumes returns be - T-distributed and thus has a 3rd parameter (nu) that controls the - mass in the tails. + """Run Bayesian model assuming returns are normally distributed. Parameters ---------- @@ -149,7 +145,11 @@ def model_returns_normal(data, samples=500): def model_returns_t(data, samples=500): - """Run Bayesian model assuming returns are normally distributed. + """Run Bayesian model assuming returns are Student-T distributed. + + Compared with the normal model, this model assumes returns are + T-distributed and thus have a 3rd parameter (nu) that controls the + mass in the tails. Parameters ---------- diff --git a/pyfolio/timeseries.py b/pyfolio/timeseries.py index aafcdfef..dec1f041 100644 --- a/pyfolio/timeseries.py +++ b/pyfolio/timeseries.py @@ -76,18 +76,9 @@ def max_drawdown(returns): return np.nan df_cum_rets = cum_returns(returns, starting_value=100) + cum_max_return = df_cum_rets.cummax() - MDD = 0 - DD = 0 - peak = -99999 - for value in df_cum_rets: - if (value > peak): - peak = value - else: - DD = (peak - value) / peak - if (DD > MDD): - MDD = DD - return -1 * MDD + return df_cum_rets.sub(cum_max_return).div(cum_max_return).min() def annual_return(returns, period=DAILY): @@ -925,7 +916,7 @@ def calc_distribution_stats(x): def get_max_drawdown_underwater(underwater): - """Determines peak, valley, and recovery dates given and 'underwater' + """Determines peak, valley, and recovery dates given an 'underwater' DataFrame. An underwater DataFrame is a DataFrame that has precomputed