Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Runtime error

Hello, I'm new to Quantopian and I'm stuck by an runtime error in the schedule_function.

Yet it seems to me that the code is correct, can someone help me?
Thank you for your help.

The code is :

def initialize(context):  
    context.jj = sid(4151)  
    schedule_function(check_bands, date_rules.every_day())  
def check_bands(context,Data):  
    cur_price = data.current(context.jj, 'price')  
    prices = data.history(context.jj, 'price', 20, '1d')  
    avg = prices.mean()  
    std = prices.std()  
    lower_band = avg - 2*std  
    upper_band = avg + 2*std  

    if cur_price <= lower_band:  
        order_target_percent(context.jj,1.0)  
        print ('Achat')  
    elif cur_price >= upper_band:  
        order_target_percent(context.jj,-1.0)  
        print ('Vente à découvert')  
    else:  
        pass

    record(upper=upper_band,  
           lower = lower_band, mavg_20=avg, price=cur_price)  
2 responses

@Olivier ,

Try this:


def initialize(context):  
    context.jj = sid(4151)  
    schedule_function(check_bands, date_rules.every_day()) 

def check_bands(context,data):  
    cur_price = data.current(context.jj, 'price')  
    prices = data.history(context.jj, 'price', 20, '1d')  
    avg = prices.mean()  
    std = prices.std()  
    lower_band = avg - 2*std  
    upper_band = avg + 2*std  

    if cur_price <= lower_band:  
        order_target_percent(context.jj, 1.0)  
        print ('Achat')  
    elif cur_price >= upper_band:  
        order_target_percent(context.jj, -1.0)  
        print ('Vente à découvert')  
    else:  
        pass

    record(upper = upper_band, lower = lower_band, mavg_20 = avg, price = cur_price)  

Thank you very much @Vladimir