kieran-mackle / AutoTrader

A Python-based development platform for automated trading systems - from backtesting to optimisation to livetrading.

Home Page:https://kieran-mackle.github.io/AutoTrader/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KeyError: -1 in find_swings()

ihopethiswillfi opened this issue · comments

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.