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

Errors in calculating drawdowns? #354

Open
BAMBAMGit opened this issue May 29, 2024 · 2 comments
Open

Errors in calculating drawdowns? #354

BAMBAMGit opened this issue May 29, 2024 · 2 comments

Comments

@BAMBAMGit
Copy link

Is it possible the max drawdown periods are giving the wrong dates as an output? For example see this:

Here I'm finding the max drawdown for the dot-com and great recession crashes for QQQ.


!pip install quantstats

# need to install arial font with matplotlib
import matplotlib.font_manager as fm
import matplotlib.pyplot as plt
# arial_path = '/content/drive/MyDrive/arial.ttf'
# fm.fontManager.addfont(arial_path)  # Register the Arial font with Matplotlib
# plt.rcParams['font.family'] = 'Arial'

import yfinance as yf
df = yf.download('QQQ', start='2000-01-01', end='2020-01-01')

import quantstats as qs
qs.extend_pandas()
returns = df.Close.pct_change()
qs.reports.full(returns, "QQQ")

OUTPUT:
_[Worst 5 Drawdowns]

Start Valley End Days Max Drawdown 99% Max Drawdown

1 2000-03-28 2002-10-09 2016-09-02 6003 -82.96 -80.06
2 2018-08-30 2018-12-24 2019-04-16 230 -23.16 -19.77
3 2019-05-06 2019-06-03 2019-07-02 58 -10.98 -8.98
4 2018-03-13 2018-04-02 2018-06-01 81 -10.67 -10.02
5 2000-01-24 2000-01-28 2000-02-02 10 -10.65 -7.27_


# start of drawdown period
start_draw_down = df[df.index == '2000-03-28']

# end of drawdown period
end_draw_down = df[df.index == '2016-09-02']

# double checking a date before end of drawdown period where close has already broken out of drawdown period
earlier_date_in_drawdown_period = df[df.index == '2016-08-30']


print(start_draw_down.Close)
print(end_draw_down.Close)
print(earlier_date_in_drawdown_period.Close)

OUTPUT:
Date
2000-03-28 114.75
Name: Close, dtype: float64
Date
2016-09-02 117.120003
Name: Close, dtype: float64
Date
2016-08-30 116.559998
Name: Close, dtype: float64

Note, the 2016-08-30 has already surpassed the close from the previous high water mark. Therefore the drawdown end date that quant stats is calculating appears erroneous.Thoughts? Maybe I'm missing something.

@RKMaynard
Copy link

RKMaynard commented Jun 7, 2024

We have also seen errors in the drawdown dates. However, this repo seems to no longer be maintained, so we are pushing our mods to quantstats-lumi. We will replicate this issue there for tracking.

@grzesir
Copy link

grzesir commented Jul 30, 2024

Check out https://github.com/Lumiwealth/quantstats_lumi, which is being updated regularly. We are a fork of this library that is being maintained by Lumiwealth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants