quantstats icon indicating copy to clipboard operation
quantstats copied to clipboard

IndexError: list index out of range

Open shirishaardak opened this issue 4 years ago • 2 comments

Code

#Read CSV file with Pandas stock_price = pd.read_csv('./data/NIFTY_15minute.csv')

stock_price.columns = ['date', 'Open', 'High', 'Low', 'Close', 'volume', 'oi']

Remove time

stock_price['date'] = pd.to_datetime(stock_price['date']).dt.date

set index as date

stock_price['date'] = stock_price.set_index(['date'], inplace=True)

daily returns

stock_price['Pct Change'] = (stock_price['Close'] - stock_price['Open'])/ stock_price['Open']

pct_change = stock_price['Pct Change']

print(pct_change)

quantstats.reports.basic(pct_change)

issue

date 2021-01-01 0.000353 2021-01-01 0.000524 2021-01-01 -0.000517 2021-01-01 0.000642 2021-01-01 -0.000317 ... 2021-07-19 -0.001171 2021-07-19 -0.001592 2021-07-19 0.002279 2021-07-19 0.000270 2021-07-19 0.000432 Name: Pct Change, Length: 3358, dtype: float64 [Performance Metrics]

Traceback (most recent call last): File "d:/Algorithmic Trading Proejct/algorithmic-trading-strategies/strategies/test.py", line 25, in quantstats.reports.basic(pct_change) File "C:\Users\91989\anaconda3\lib\site-packages\quantstats\reports.py", line 280, in basic metrics(returns=returns, benchmark=benchmark, File "C:\Users\91989\anaconda3\lib\site-packages\quantstats\reports.py", line 327, in metrics dd = _calc_dd(df, display=(display or "internal" in kwargs)) File "C:\Users\91989\anaconda3\lib\site-packages\quantstats\reports.py", line 604, in _calc_dd dd_info = _stats.drawdown_details(dd) File "C:\Users\91989\anaconda3\lib\site-packages\quantstats\stats.py", line 576, in drawdown_details _dfs[col] = _drawdown_details(drawdown[col]) File "C:\Users\91989\anaconda3\lib\site-packages\quantstats\stats.py", line 553, in _drawdown_details dd = drawdown[starts[i]:ends[i]] IndexError: list index out of range

shirishaardak avatar Jul 22 '21 06:07 shirishaardak

I have the exact same issue, but then I figure out that that I had results for the same date. For example: 2015-12-04 1.2% 2015-12-04 -.5%

As soon as I cleaned the data, the problem went away.

chadhumphrey avatar Oct 19 '21 21:10 chadhumphrey

Oh yeah that fixed it for me to thanks. Passing in a dataframe instead of a series, or having multiple returns on one date, are my most common errors.

wassname avatar Aug 12 '22 05:08 wassname