Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save santatic/f4d766b4f5f6c74a7f6bb7ccc681ae73 to your computer and use it in GitHub Desktop.
Save santatic/f4d766b4f5f6c74a7f6bb7ccc681ae73 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