-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why do my results seem to be inaccurate? #2
Comments
Let me given an example to show that this library cannot even calculate an Exponential Moving Average - one of the most basic averages.
This prints:
In the first result we take the 3-period EMA over Now we take the EMA again, but this time we prepend a Now if you think that TA-Lib may iterate the other way, simply replace
Only one new value This is quite significant because there is a ton of Java-based projects that use this library here. It's the first go-to library for a lot of projects and trading interfaces. I'm surprised nobody else noticed or made an issue. |
I can't replicate this issue in python, is it possible your java wrapper malforms data? import talib
import numpy
input = numpy.array([5.0, 4.0, 3.0, 2.0, 1.0])
print(talib.EMA(input, timeperiod = 3)) # [nan nan 4. 3. 2.]
input = numpy.array([5.0, 4.0, 3.0, 2.0, 1.0, 10.0])
print(talib.EMA(input, timeperiod = 3)) # [nan nan 4. 3. 2. 6.]
input = numpy.array([5.0, 4.0, 3.0, 2.0, 1.0, 10.0, 5.0])
print(talib.EMA(input, timeperiod = 3)) # [nan nan 4. 3. 2. 6. 5.5] |
@sebbie In Python it does not reverse data, I guess this is a source of confusion. But if you add something in the beginning, end results will change, even though the value is beyond provided time period. I have no idea what timeperiod actually does, because it does not prevent calculating data on values before that period. |
Ignatius, Your "short warning to the community" is clearly wrong and should be deleted. Ignatius: - Because TA-Lib iterates from the end to the beginning. Ignatious: - Since the first entry in the list represents the newest entry.
Also pay attention to other return values from ema() call. For example: do you know why it gives you back "outBeginIndex" along with "outLength"?? Are those there just for fun? I didn't go that far as to test TA-Lib with AI and never build "automatised tests using reflection" around it, but I bet ema() works just fine! Let's take some test series data and try! Here's your slightly modified example:
And it's output:
|
Thank you Dmitry for the example. It seems indeed that ta-lib produces the correct results if you use it right, so I will close this issue. I note however that I was not the only one who was misled by this libraries behaviour output. The source of the confusion becomes clear when comparing the Python output to the Java output. The EMA(3) for
But in Java it is
The natural assumption is that the zeros at the end of the array represent the undefined values of the EMA (the And yep, in retrospect it seems fairly stupid of me that I didn't discover this before opening this issue. Sometimes you go down some rabbit-hole during debugging, and the right thought just does not occur to you anymore... |
Edit: This was previously a false warning to the community not to use this library - I apologise for the false alarm because of my own unflattering misunderstanding. Turns out that I had made wrong assumptions about how the library processes input and returns values.
As long as you understand that
You should be fine 🙂
The text was updated successfully, but these errors were encountered: