TA-Lib / ta-lib-python

Python wrapper for TA-Lib (http://ta-lib.org/).
http://ta-lib.github.io/ta-lib-python
Other
9.46k stars 1.74k forks source link

Why I'm getting so many NaNs on the tail of MA function return? #539

Open nameless0704 opened 2 years ago

nameless0704 commented 2 years ago

1662364731009

nameless0704 commented 2 years ago

the same with function BBANDS...I don't think there is NaN interfering because the last 3 values are non-NaN but still getting NaN returns.

mrjbq7 commented 2 years ago

You will find NaN at the beginning due to the lookback period not having enough values to calculate, and then you can find NaN later if your data set has NaN in it in the middle.

On Sep 5, 2022, at 1:38 AM, nameless0704 @.***> wrote:

 the same with function BBANDS...I don't think there is NaN interfering because the last 3 values are non-NaN but still getting NaN returns.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.

mrjbq7 commented 1 year ago

Added a note about NaN handling b0439e6e0565647e21b1ceee245bad4fac55aad6

ihopethiswillfi commented 1 year ago

Why is the last MA a NaN here?
The timeperiod is 3. And clearly the last 5 values of the input are not NaNs.

trufanov-nok commented 1 year ago

default MA is SMA, but TA-Lib calculates it in a most efficient way: by adding the next bar, removing the bar[-period] and deviding by timeperiod. So it has a rolling sum of bars in a middle of period. Any NaN that hits this rolling sum will spoil the sum and all values after it will be NaNs. TA-Lib doesn't expect any appearance of NaN values in input data.