average_true_range(..., window=N) raises IndexError in N if greater than length of passed series
flaviovs opened this issue · 0 comments
flaviovs commented
Not sure about the expected behaviour of average_true_range(..., window=N)
when N > len(series)
, so reporting anyway.
How to reproduce:
import pandas as pd
from ta.volatility import average_true_range
df = pd.DataFrame({'H': [3, 4, 5, 6, 7],
'L': [1, 2, 3, 4, 5],
'C': [2, 3, 4, 5, 6]}, index=pd.date_range('2021-01-01', periods=5))
average_true_range(high=df['H'], low=df['L'], close=df['C'], window=6)
Note: same results if using AverageTrueRange
class.
NB: I hope this is a valid bug report, since Pandas "rolling" functions return arrays of np.NaN
when the window is greater than the passed series/dataframe, (no exception is raised). Example:
import pandas as pd
s = pd.Series([2, 3, 4, 5, 6], index=pd.date_range('2021-01-01', periods=5))
print(s.rolling(6).mean())
# Prints:
# 2021-01-01 NaN
# 2021-01-02 NaN
# 2021-01-03 NaN
# 2021-01-04 NaN
# 2021-01-05 NaN
# Freq: D, Name: C, dtype: float64