bta-lib icon indicating copy to clipboard operation
bta-lib copied to clipboard

Indicator on indicator gives different values from bt.indicators

Open slangda opened this issue 3 years ago • 2 comments

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 avatar Apr 01 '21 12:04 slangda

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.

slangda avatar Apr 01 '21 12:04 slangda

but unmaintained?

adrianog avatar Apr 13 '21 22:04 adrianog