Back to Community
Slicing of history()

Hi everyone,

I was wondering why slicing the history function causes troubles when computing indicators with Talib? Here, I try to calculate a SMA with a 9 days lag, however I get an error.

Laurent

import talib

def initialize(context):  
    set_universe(universe.DollarVolumeUniverse(90, 100))

def handle_data(context, data):  
    prices = history(300, '1d', 'price')  
    prices = prices.iloc[:290]  
    print prices.tail(20)  
    ma_200 = prices.apply(talib.SMA, timeperiod=200).iloc[-1]  
    print ma_200

Exception: inputs are all NaN  
There was a runtime error on line 11.  
2 responses

Try doing
prices=history(300,'1d','price').dropna(axis=1)

Have not tried it but I believe that should work.

Good luck

Hi Serge,

Thanks a lot for your help, it worked perfectly!

Best,

L