Skip to content

Commit

Permalink
Merge pull request #281 from devinstevenson/master
Browse files Browse the repository at this point in the history
vectorize max drawdown and fix doc strings
  • Loading branch information
twiecki committed Feb 3, 2016
2 parents 035093a + b6bb0be commit 73e91bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
12 changes: 6 additions & 6 deletions pyfolio/bayesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down Expand Up @@ -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
----------
Expand Down
15 changes: 3 additions & 12 deletions pyfolio/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 73e91bc

Please sign in to comment.