Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
WARN numpy/lib/nanfunctions.py:319: RuntimeWarning: All-NaN slice encountered

history() high and low each generate this warning, different lines, 319 and 220, also one is slice and the other axis:

null:null WARN numpy/lib/nanfunctions.py:319: RuntimeWarning: All-NaN slice encountered
null:null WARN numpy/lib/nanfunctions.py:220: RuntimeWarning: All-NaN axis encountered

def initialize(context):  
    symbols('AAIT', 'AAME')

def handle_data(context, data):  
    #history(20, '1d', 'open_price')  
    history(20, '1d', 'high')  
    history(20, '1d', 'low')  
    #history(20, '1d', 'close_price')  
7 responses

Hi Gary,

I wasn't sure if you were posting a solution or just more info on the issue. I had actually figured out the issue a few days ago. With your specific code, AAME didn't exist before 2012, so if you're running your backtest before 2012, you're going to encounter All-NaN error warnings.

I ran a quick test and if I changed my backtest to be from 2013 and onward, it was fine. Also, changing the symbol AAME to something else that existed back then also worked. Basically, if the history function is unable to get prices for the time periods you specified, you'll get that warning.


It's a lovely bug Quantopian surely wants to fix. In the scenario where a symbol didn't exist, the expected message is different from what's being seen here. One might think set_symbol_lookup_date() could come into play, I don't think so. It also applies to other symbols, pretty common, this is just a simplified example.

My dates above were 2015 only.
Try the date range 2015-03-16 to 2015-03-20, both were trading during that week.
AAME only: No warning
AAIT only: No warning
AAIT and AAME together: Crytic RuntimeWarning

AAME data goes back to 1978 in google finance so I think you must have meant AAIT.

img credit

History is feeding on the universe rather than what's in data, maybe the warning could simply be suppressed.

Happens with certain stocks only in combination with others,
newer stocks when backtests include before they were listed.
More code to reproduce the error below, use 2013-09-11 to 2013-09-13 for example
(or same dates using SHOP, SHAK, BABA etc or any recent IPO instead of DBAP)

def initialize(context):  
    set_symbol_lookup_date('2015-06-01')  
    context.stocks_tech = symbols('TSLA')  
    context.stocks_bank = symbols('JPM', 'BAC')  
    context.stocks_hedg = symbols('DBAP')   # comment this and the problem disappears  
                                            #   yet this line by itself won't produce the error.  
def handle_data(context, data):  
    history(3, '1d', 'high')   # RuntimeWarning: All-NaN slice  
    history(3, '1d', 'low')    # RuntimeWarning: All-NaN axis  
    history(3, '1d', 'price')  
2013-05-01null:nullWARNnumpy/lib/nanfunctions.py:319: RuntimeWarning: All-NaN slice encountered  
2013-05-01null:nullWARNnumpy/lib/nanfunctions.py:220: RuntimeWarning: All-NaN axis encountered  

(High and low are used for stochastics indicator in this instance)

Hey Gary, we've suppressed these warning to make the logs friendlier. Now they will appear only at the top of your backtest. I tested your code snippet and it checks out!

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.

Any chance these warnings can be made to not appear at all?
Live/real shows up every day repeatedly.

No plans for this yet, but I'll see what I can do