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

Streaming API does not give the same result

Open DaxMao opened this issue 4 years ago • 3 comments

For some functions it is not working well:

import numpy as np
import talib
from talib import stream

close = np.array([.5, .7, .7, .6, .7, .8, .7, .7, .7, .6, .5, .5, .6, .6, .7, .8, .7, .7, .7, .6, .5, .5, .6])

print(talib.CMO(close)[-1])
print(stream.CMO(close))

The results are:

4.209286980682376
-11.111111111111105

DaxMao avatar Jul 17 '21 15:07 DaxMao

I believe this issue is due to "memory" in the Function API that is not available in the Streaming API.

>>> a = np.random.randn(15)

# with exact same data:
>>> talib.CMO(a, 14)
array([        nan,         nan,         nan,         nan,         nan,
               nan,         nan,         nan,         nan,         nan,
               nan,         nan,         nan,         nan, -1.06910005])

>>> stream.CMO(a, 14)
-1.069100046167708

# with more data in the history
>>> talib.CMO(a, 5)
array([         nan,          nan,          nan,          nan,
                nan,  13.15890374,  14.02364124, -13.26545769,
         2.12746979,  16.41988121,   0.44171192, -44.24433125,
        14.87262214,  -2.22058414,  -3.00791912])
>>> stream.CMO(a, 5)
-14.102062814919664

mrjbq7 avatar Jul 17 '21 16:07 mrjbq7

(The Streaming API only considers timeperiod observations)

mrjbq7 avatar Jul 17 '21 16:07 mrjbq7

Oh, I see. Thanks!

DaxMao avatar Jul 18 '21 03:07 DaxMao