Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Help - Exception: inputs are all NaN

Hey everyone, I am hoping that someone with a little more experience has seen this before and can point me in the right direction. I learn best by doing, so I started hacking around with some of the example algorithms and I am currently stuck with an error message that does not give me any clues on what to try next.
I was trying to use the ta.RSI example with a universe instead of a single security, and it fails about a third of the way in with the attached error message. I get a similar error message if I switch out the RSI func for MACD (though it seems to fail on a different day)

Here is the error message:

Exception: inputs are all NaN  
File test_algorithm_sycheck.py:15, in handle_data  
File /zipline/transforms/batch_transform.py:202, in handle_data  
File /zipline/transforms/batch_transform.py:267, in get_transform_value  
File /zipline/transforms/ta.py:54, in zipline_wrapper  
File abstract.pyx:331, in talib.abstract.Function.__call__ (talib/abstract.c:5815)  
File abstract.pyx:358, in talib.abstract.Function.__call_function (talib/abstract.c:6324)  
File func.pyx:7544, in talib.func.RSI (talib/func.c:67938)  

My best guess is that it is loading NaN somewhere in data when calculating the RSI, so this leads me to believe that it happens when the universe changes, but from reading the documentation it sounds like that should not be an issue.

Any thoughts on what I need to do to fix this? Any help is appreciated
*note: I did submit feedback, but I am impatient and I figure the community is full of smart people, so we will see who is quicker :)

11 responses

I think it's a tie - I just replied to your feedback email, too!

You've hit a bug in our talib implementation. What's happening is that a security is leaving the universe, and when that happens it stops being updated, but talib is still trying to calculate for that stock.

There's probably a few hacks you could do, like buy a share of every stock so it never leaves the universe, but really we need to fix the bug. I'll let you know when that happens.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Impressive quickness, thanks Dan!

I believe that this is fixed. I'm sure there are other ways still to trigger a NaN error with talib, but we changed it so that it is much less likely, and therefore much more usable.

looks good. Thanks Dan

Hi Dan,

A few months ago I noticed that the error described in this thread remains pretty prevalent when using talib.ATR(). Has this ever been noticed, and have there every been any efforts to fix?

Thanks

I have same issue as Frank. Hope to get some updates about the issue.

I'm having a similar issue with talib.SAR. I'll be looking forward to receiving updates, as well. Here is my code snippet that fails after the algo has been running for a few days:

H = data.history(security,'high', 2, '1d').dropna()  
L = data.history(security,'low', 2, '1d').dropna()  
ta_SAR = talib.SAR(H, L, 0.02, 0.2)  

The original issue described 3 years ago is long resolved. There are many reasons for NaNs to appear, the majority of them are correct behavior. Please either start a new thread with an example to debug, or contact support at [email protected]. Thanks.

Not for me.

def before_trading_start(context, data):
context.security_listF = {}
context.can_trade = 0

context.security_list = [symbol('MMM'),symbol('AXP'),symbol('AAPL'),symbol('BA'),symbol('CAT'),symbol('CVX'),symbol('CSCO'),symbol('KO'),symbol('DIS'),symbol('DD'),symbol('XOM'),symbol('GE'),symbol('GS'),symbol('HD'),symbol('IBM'),symbol('INTC'),symbol('JNJ'),symbol('JPM'),symbol('MCD'),symbol('MRK'),symbol('MSFT'),symbol('NKE'),symbol('PFE'),symbol('PG'),symbol('TRV'),symbol('UTX'),symbol('UNH'),symbol('VZ'),symbol('V'),symbol('WMT')]  

def my_rebalance(context,data):

 pc = data.history(context.security_list,'price',bar_count=5,frequency='1d')  
 op = data.history(context.security_list,'open',bar_count=1,frequency='1d')  
 lo = data.history(context.security_list,'price',bar_count=60,frequency='1d')  

 for s in context.security_list:  
    rsi = talib.RSI(lo[s], timeperiod=14)[-1]  
    if rsi < 20:  
        context.security_listF[s] = s  

the same problem met: is there a way to skip the current process if it returns Nan.

ema12 = talib.EMA(prices_weekly[stock],12)
ema26 = talib.EMA(prices_weekly[stock],26)
DIF = ema12 - ema26
DEA = talib.EMA(DIF,9)

If you want to skip the process if Nan just do this:

 if not prices_weekly[stock].isnull().all():  
      ema12 = talib.EMA(prices_weekly[stock],12)  
      ema26 = talib.EMA(prices_weekly[stock],26)  
      DIF = ema12 - ema26  
      DEA = talib.EMA(DIF,9)