Skip to content

Instantly share code, notes, and snippets.

@lamres
Created March 17, 2020 17:40
Show Gist options
  • Save lamres/69006be9794d9e359643e2a28538a95f to your computer and use it in GitHub Desktop.
Save lamres/69006be9794d9e359643e2a28538a95f to your computer and use it in GitHub Desktop.
def show_worst_drawdown_periods(returns, top=5):
"""
Prints information about the worst drawdown periods.
Prints peak dates, valley dates, recovery dates, and net
drawdowns.
Parameters
----------
returns : pd.Series
Daily returns of the strategy, noncumulative.
- See full explanation in tears.create_full_tear_sheet.
top : int, optional
Amount of top drawdowns periods to plot (default 5).
"""
drawdown_df = timeseries.gen_drawdown_table(returns, top=top)
return drawdown_df.sort_values('Net drawdown in %', ascending=False)
'''
utils.print_table(
drawdown_df.sort_values('Net drawdown in %', ascending=False),
name='Worst drawdown periods',
float_format='{0:.2f}'.format,
)
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment