ta
ta copied to clipboard
IndexError on ADX
Series length = 17, window = 14:
from io import StringIO
import pandas as pd
from ta.trend import adx
DATA = '''
DATE O H L C
2019-12-05 0.60 0.62 0.60 0.62
2019-12-06 0.61 0.61 0.61 0.61
2019-12-09 0.61 0.61 0.61 0.61
2019-12-10 0.60 0.60 0.60 0.60
2019-12-11 0.60 0.60 0.58 0.58
2019-12-12 0.59 0.59 0.58 0.58
2019-12-13 0.56 0.58 0.56 0.58
2019-12-16 0.55 0.57 0.55 0.56
2019-12-17 0.57 0.58 0.56 0.58
2019-12-18 0.59 0.59 0.58 0.58
2019-12-19 0.55 0.57 0.52 0.52
2019-12-20 0.51 0.56 0.51 0.53
2019-12-23 0.54 0.54 0.54 0.54
2019-12-24 0.53 0.57 0.53 0.57
2019-12-27 0.60 0.60 0.55 0.60
2019-12-30 0.62 0.62 0.60 0.60
2019-12-31 0.60 0.64 0.59 0.64
'''
df = pd.read_csv(StringIO(DATA), sep=' ', index_col='DATE', skipinitialspace=True, parse_dates=['DATE'])
print(len(df))
# '17'
adx(high=df['H'], low=df['L'], close=df['C'], window=14)
# ~/.venvs/lib/python3.7/site-packages/ta/trend.py:768: RuntimeWarning: invalid value encountered in double_scalars
# dip[i] = 100 * (self._dip[i] / self._trs[i])
# ~/.venvs/lib/python3.7/site-packages/ta/trend.py:772: RuntimeWarning: invalid value encountered in double_scalars
# din[i] = 100 * (self._din[i] / self._trs[i])
# Traceback (most recent call last):
# File "test.py", line 31, in <module>
# adx(df['H'], df['L'], df['C'], window=14)
# File "~/.venvs/lib/python3.7/site-packages/ta/trend.#py", line 1251, in adx
# high=high, low=low, close=close, window=window, fillna=fillna
# File "~/.venvs/lib/python3.7/site-packages/ta/trend.py", line 777, in adx
# adx_series[self._window] = directional_index[0 : self._window].mean()
# IndexError: index 14 is out of bounds for axis 0 with size 4
Issue stops with window set to 8 or less (no exception is raised at least, didn't check calculation), although the two warnings are still issued.