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

Why does it become all zeros after flattening in NATR, while this doesn't happen in other APIs? #653

Open
gucasbrg opened this issue Jun 4, 2024 · 2 comments

Comments

@gucasbrg
Copy link

gucasbrg commented Jun 4, 2024

import numpy as np
import talib

def _ta_natr_14(x1, x2, x3):
    t = 14
    x1 = x1.flatten()
    x2 = x2.flatten()
    x3 = x3.flatten()
    print(np.nan_to_num(talib.NATR(x1, x2, x3, timeperiod=t))[:100])

def _ta_natr_14_qs(x1, x2, x3):
    t = 14
    print(np.nan_to_num(talib.NATR(x1, x2, x3, timeperiod=t))[:100])


x1 = np.load('x1.npy')
x2 = np.load('x2.npy')
x3 = np.load('x3.npy')
_ta_natr_14(x1, x2, x3)
_ta_natr_14_qs(x1, x2, x3)

data.zip

@mrjbq7
Copy link
Collaborator

mrjbq7 commented Jun 5, 2024

It doesn't become all zeros, but I'm not sure why the initial values are ~0, have to look at it closer maybe.

In [1]: import numpy as np

In [2]: import talib as ta

In [3]: x1 = np.load('x1.npy')
   ...: x2 = np.load('x2.npy')
   ...: x3 = np.load('x3.npy')
   ...: 

In [4]: r = ta.NATR(x1, x2, x3, timeperiod=14)

In [6]: r
Out[6]: 
array([          nan,           nan,           nan, ..., -252.67133272,
       -241.77978634, -222.86091276])

In [7]: r[:100]
Out[7]: 
array([            nan,             nan,             nan,             nan,
                   nan,             nan,             nan,             nan,
                   nan,             nan,             nan,             nan,
                   nan,             nan, 0.00000000e+000, 2.15081535e-314,
       2.15084699e-314, 2.15081535e-314, 2.38508723e-314, 2.38509025e-314,
       2.15358054e-314, 2.15084699e-314, 2.15358054e-314, 2.38508794e-314,
       2.38508621e-314, 2.15085935e-314, 2.38508462e-314, 2.15085935e-314,
       2.38508804e-314, 2.15357763e-314, 2.15084699e-314, 2.38508555e-314,
       2.38508851e-314, 2.15082759e-314, 2.15084699e-314, 2.15082759e-314,
       2.38508968e-314, 2.38508612e-314, 2.14447468e-314, 2.15084699e-314,
       2.14447468e-314, 2.38508859e-314, 2.38508934e-314, 2.15075115e-314,
       2.15084699e-314, 2.15075115e-314, 2.38508427e-314, 2.38508714e-314,
       2.15077545e-314, 2.15084699e-314, 2.15077545e-314, 2.38508560e-314,
       2.38508984e-314, 2.15358013e-314, 2.15084699e-314, 2.15358013e-314,
       2.38508956e-314, 2.38508536e-314, 2.14564750e-314, 2.15084699e-314,
       2.14564750e-314, 2.38508740e-314, 2.38508882e-314, 2.15079954e-314,
       2.15084699e-314, 2.15079954e-314, 2.38508702e-314, 2.38508602e-314,
       2.15059941e-314, 2.15084699e-314, 2.15059941e-314, 2.38508657e-314,
       2.38508885e-314, 2.14868621e-314, 2.15084699e-314, 2.14868621e-314,
       2.38508531e-314, 2.38508674e-314, 2.15080767e-314, 2.15084699e-314,
       2.15080767e-314, 2.38508918e-314, 2.38508638e-314, 2.15082959e-314,
       2.15084699e-314, 2.15082959e-314, 2.38508799e-314, 2.38508662e-314,
       2.15086285e-314, 2.15084699e-314, 2.15086285e-314, 2.38508517e-314,
       2.38508735e-314, 2.14662694e-314, 2.38508631e-314, 2.14662694e-314,
       2.38508690e-314, 2.14762244e-314, 2.15084699e-314, 2.38508823e-314])

In [8]: r[100:200]
Out[8]: 
array([ 2.38508633e-314,  2.15072236e-314,  2.38508538e-314,
        2.15072236e-314,  2.38508749e-314,  2.15086156e-314,
        2.38509105e-314,  2.38509108e-314,  2.15483403e-314,
        2.15084699e-314,  2.38509110e-314,  2.38509112e-314,
        2.14564861e-314,  2.38509115e-314,  2.14564861e-314,
        2.38509117e-314,  2.15078548e-314,  2.15084699e-314,
        2.38509119e-314,  2.38509122e-314,  2.14564864e-314,
        2.38509124e-314,  2.14564864e-314,  2.38509127e-314,
        2.14564583e-314,  2.15084699e-314,  2.38509129e-314,
        2.38509131e-314,  2.15073361e-314,  2.38509134e-314,
        2.15073361e-314,  2.38509136e-314,  2.15072353e-314,
        2.15084699e-314,  2.38509138e-314,  2.38509141e-314,
        2.15073361e-314,  2.38509143e-314,  2.15073361e-314,
        2.38509145e-314,  2.14564618e-314,  2.38509148e-314,
        2.38509150e-314,  2.15491235e-314,  2.15084805e-314,
        2.38509153e-314,  2.14712372e-314,  2.38509155e-314,
        2.38509157e-314,  2.15491251e-314,  2.15084805e-314,
        2.38509160e-314,  2.14712293e-314,  2.38509162e-314,
        2.38509164e-314,  2.15491238e-314,  2.15084699e-314,
        2.38509167e-314,  2.38509169e-314,  2.15073361e-314,
        2.38509172e-314,  2.15073361e-314,  2.38509174e-314,
        7.27720355e+001,  7.11351962e+001,  6.96721234e+001,
        7.04181050e+001,  7.54645854e+001,  8.55322620e+001,
        9.53305916e+001,  1.04393368e+002,  1.10398671e+002,
        1.11875702e+002,  1.13083248e+002,  1.14092627e+002,
        1.15133525e+002,  1.16161142e+002,  1.23706637e+002,
        1.31069486e+002,  1.38575068e+002,  1.46799978e+002,
        1.49581612e+002,  1.55800334e+002,  1.69201162e+002,
        2.07889468e+002,  7.58211146e+002,  1.12955155e+004,
        1.65019307e+002,  1.32951872e+002,  1.24512123e+002,
        1.32892189e+002,  1.47207693e+002,  1.69148266e+002,
        2.04277895e+002,  2.67542693e+002,  4.09486356e+002,
        7.09521998e+002,  9.90584944e+002,  6.69927309e+002,
       -3.94789948e+003])

@mrjbq7
Copy link
Collaborator

mrjbq7 commented Jun 5, 2024

In [7]: r = ta.NATR(x1.flatten(), x2.flatten(), x3.flatten(), timeperiod=14)

In [8]: r[:100]
Out[8]: 
array([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
       nan,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])

In [9]: r[100:200]
Out[9]: 
array([    0.        ,     0.        ,     0.        ,     0.        ,
           0.        ,     0.        ,     0.        ,     0.        ,
           0.        ,     0.        ,     0.        ,     0.        ,
           0.        ,     0.        ,     0.        ,     0.        ,
           0.        ,     0.        ,     0.        ,     0.        ,
           0.        ,     0.        ,     0.        ,     0.        ,
           0.        ,     0.        ,     0.        ,     0.        ,
           0.        ,     0.        ,     0.        ,     0.        ,
           0.        ,     0.        ,     0.        ,     0.        ,
           0.        ,     0.        ,     0.        ,     0.        ,
           0.        ,     0.        ,     0.        ,     0.        ,
           0.        ,     0.        ,     0.        ,     0.        ,
           0.        ,     0.        ,     0.        ,     0.        ,
           0.        ,     0.        ,     0.        ,     0.        ,
           0.        ,     0.        ,     0.        ,     0.        ,
           0.        ,     0.        ,     0.        ,    72.77203545,
          71.13519618,    69.67212345,    70.41810497,    75.46458542,
          85.53226199,    95.33059159,   104.3933683 ,   110.39867053,
         111.87570231,   113.08324841,   114.09262749,   115.13352545,
         116.16114151,   123.70663687,   131.06948569,   138.57506813,
         146.79997804,   149.5816119 ,   155.80033379,   169.20116231,
         207.88946832,   758.21114577, 11295.51548872,   165.01930733,
         132.9518719 ,   124.51212282,   132.89218869,   147.20769277,
         169.14826558,   204.27789478,   267.54269313,   409.48635643,
         709.52199833,   990.58494426,   669.92730938, -3947.89947949])

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