Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Record : TypeError: Non-numeric value 0 2008-01-02 00:00:00+00:00 inf

Hi,

Any reason I am getting a TypeError: Non-numeric value 0 2008-01-02 00:00:00+00:00 inf in the attached algo. i am just testing the batch transform pandas dataframe logic with a standard ewma crossover normalized.

Additionally, if i have two moving averages ie a 50 and a 100 day , am i using the correct window length? Struggling to get my head around that function so any help is much appreciated.

3 responses
import pandas


def initialize(context):  
    context.stocks = sid(1787)

@batch_transform(refresh_period=1,window_length=40)  
def get_EMA(datapanel):  
    slow = 50  
    fast = 100  
    vol_window = 50  

    ewma_a = pandas.stats.moments.ewma(datapanel['price'], span=slow)  
    ewma_b = pandas.stats.moments.ewma(datapanel['price'], span=fast)  

    ewma_diff = pandas.DataFrame(ewma_a[1787] - ewma_b[1787])  

    vol = pandas.DataFrame(pandas.stats.moments.ewmvol(ewma_diff[1787], span=vol_window))  
    EMA = ewma_diff[1787]/vol

    record(ema=EMA)  
    return EMA

def handle_data(context, data):  
    EMA = get_EMA(data)  
    if EMA is None:  
        return  

You're trying to record a dataframe rather than a single value. Try something like:

record(ema=EMA[0][39])  

P.

Thanks Peter.