kieran-mackle / AutoTrader

A Python-based development platform for automated trading systems - from backtesting to optimisation to livetrading.
https://kieran-mackle.github.io/AutoTrader/
GNU General Public License v3.0
945 stars 217 forks source link

KeyError: -1 in find_swings() #54

Closed ihopethiswillfi closed 1 year ago

ihopethiswillfi commented 1 year ago

Describe the bug KeyError: -1 when running code below.

To Reproduce

y = pd.Series([5, 10, 3, 5, 3])
swings = autotrader.indicators.find_swings(data=y, data_type='other', n=2)

Version of AutoTrader being used eg. Using version 0.7.10

Additional context Error occurs on line 405 in indicators.py: grad = [swing_data[i] - swing_data[i-1] for i in range(len(swing_data))]

This seems to me like it would always throw an error, because the first iteration will have i==0 and so i-1 will equal -1, which is expected to error. I would personally write this like: grad = [swing_data[i] - swing_data[i-1] for i in range(1, len(swing_data))] this however makes the output shorter by 1 item.