ta-lib-python icon indicating copy to clipboard operation
ta-lib-python copied to clipboard

RSI returns different values while dataset length differs

Open moonmoondog opened this issue 4 years ago • 1 comments

I am trying to generate an RSI series from an array (also tried pandas series) of close data. (Length > 10000) But when I slice the numpy array into a smaller sub dataset with [idx: idx], and run the same RSI function (same period, only the close data has shorter length) on it, the output values do not match with the original ones. Although the values generated from the sliced array roughly agree with the original one, however each of them are still up to 2-5 value off. any idea why it would happen? I have tried to slice the dataset into some larger arrays, and try that again, when the slice size gets bigger (len > 1000), the output would eventually match with the original set it seems that the RSI calculation of smaller and bigger dataset are using different methods??? I'm using python 3.8 talib 0.4.19 thank you for looking into my question

moonmoondog avatar Dec 23 '20 00:12 moonmoondog

It does look like it has an error of up to 1% in a random test case:

>>> import talib as ta
>>> import numpy as np

>>> ta.RSI(c, 10)[20:30] - ta.RSI(c[10:], 10)[10:20]
array([0.55433023, 0.16728771, 0.26774739, 0.36503846, 0.2532844 ,
       0.29130067, 0.09445057, 0.09538932, 0.28666108, 0.07085545])

>>> ta.RSI(c, 10)[20:30] / ta.RSI(c[10:], 10)[10:20]
array([1.01021091, 1.00370364, 1.00546862, 1.00682639, 1.00506591,
       1.0056012 , 1.00212166, 1.00214035, 1.00487611, 1.00154319])

It's probably something due to the smoothing method that it uses?

https://github.com/TA-Lib/ta-lib/blob/master/src/ta_func/ta_RSI.c#L341

mrjbq7 avatar Dec 24 '20 17:12 mrjbq7