Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
NaN Error i can not solve

Hi everyone,

I'm quite new to Quantopian, and python aswell for that matter and i get an error for which i do not understand the cause. The error is as follows:

Exception: inputs are all NaN There was a runtime error on line 17.

The part of the code that generates the error is the following:
line 17 is the line: sma = prices.apply(talib.SMA, timeperiod=20).iloc[-1]

import talib  
import math  
import random

def initialize(context):  
    set_universe(universe.DollarVolumeUniverse(floor_percentile=97.5, ceiling_percentile=99.5))  
    #context.stock = symbols('GOOG')  
    set_commission(commission.PerShare(cost=0.004, min_trade_cost=1))  
    context.sell_price = {'stock' : 'value'}  
    context.want_price = {'stock' : 'value'}  
    context.times = {'stock' : 'times'}  
    context.last_price = {'stock' : 'times'}  
    context.bought = {'stock' : 'bought'}  
def handle_data(context, data):  
    prices = history(25, '1m', 'price')  
    sma = prices.apply(talib.SMA, timeperiod=20).iloc[-1]  
    smapref = prices.apply(talib.SMA, timeperiod=20).iloc[-2]  
    for stock in data:  
        cash = context.portfolio.cash  
        test = context.times.get(stock.symbol)  

The code runs for a long time in minute data but it seems to be unable to run over the months januarie in the years 2013, 2014 and 2015. Is this some bug in the historical data not giving values that carrie over the year, or is there something else wrong which i do not see?

Hope anyone can help me.
Kind regards,
Dennis

2 responses

HI Dennis,

You need to check that the stock is actually trading before calculating technicals on it. With the dynamic universe stocks can be in history() but set all to NaN. This thread explains more.

Give it a go and see how you get on.

Hi James,

Thank you, i will give it a try and hope it will work!