Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vectorize drawdown #1

Merged
merged 2 commits into from
Feb 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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