Skip to content
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

The results obtained by streaming and api are very different #600

Open
gucasbrg opened this issue Jun 27, 2023 · 3 comments
Open

The results obtained by streaming and api are very different #600

gucasbrg opened this issue Jun 27, 2023 · 3 comments

Comments

@gucasbrg
Copy link

import talib as ta
from talib import stream as ta_stream
close = np.random.random(100)
output = ta.RSI(close, timeperiod=period)
latest = ta_stream.RSI(close, timeperiod=period)
print(output)
print(latest)
print(output[-1] - latest)
@mrjbq7
Copy link
Collaborator

mrjbq7 commented Jun 27, 2023 via email

@ghost
Copy link

ghost commented Jul 11, 2023

In the simplest case (SMA) a (truly) streaming api keeps the intermediate value of the sum of the window. When a new value arrives, it subtracts the last element, and adds the new one and returns the mean. (PREV_SUM - tail + head) / length.
This is why you need the intermediate state like in https://github.com/trufanov-nok/ta-lib-rt
All the indicators that use some kind of recursion need an intermediate state from which to compute the latest value, and this is not generalizable into an api, it needs adhoc implementations for each indicators

@mrjbq7
Copy link
Collaborator

mrjbq7 commented Jul 12, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants