mementum / bta-lib

Technical Analysis library in pandas for backtesting algotrading and quantitative analysis
MIT License
454 stars 106 forks source link

Indicator on indicator gives different values from bt.indicators #14

Open slangda opened 3 years ago

slangda commented 3 years ago

As I have mentioned on the community forum: https://community.backtrader.com/topic/3687/bta-lib-and-bt-indicators-deliver-different-values-when-using-indicator-on-indicator

The bta-lib indicator on indicator gives different results than when using this in backtrader internally.

The problem surfaces when you use RSI on ATR for example.

atr14 = ATR(High, Low, Close, period=14)

This will return a pandas dataframe containing NaN values.

When you feed this to the next indicator, this results in different values from Backtrader:

rsi_atr = RSI(atr14, period=7)

In order to come up with the same results, one should implement the dataframe without the NaN values.

rsi_atr = RSI(atr14.dropna(), period=7)

I am uncertain considering the setup of the bta-lib framework if the dataframe returned from the functions should be stripped of NaN values (losing the index compatibility, don't think that is good) or if bta-lib functions should drop NaN values before computations.

However, in the Backtrader implementation this is done correctly. I feel bta-lib should deliver exactly the same results.

slangda commented 3 years ago

Oh and thank you for this library. I was writing my own implementations and have tried TA-Lib, but this is the best library around IMHO.

adrianog commented 3 years ago

but unmaintained?