IndexError: list index out of range
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
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.
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.