Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Is something wrong in my schedule function?

Hi everyone!
I am a beginner in quantopian. I ran the code for several times and I try to fix it again and again. But I still can not find out the problem with the order_target_percent, can somebody answer me what the problem is?
I am so appreciated!
Thank you in advance.

1 response

Instead of the original code

    for stock in context.long_list:  
        if stock in context.long_list:  
            order_target_percent(stock, long_weight)  
    for stock in context.short_list:  
        if stock in context.short_list:  
            order_target_percent(stock, short_weight)  

replace it with

    for stock in context.long_list.index:  
            order_target_percent(stock, long_weight)  
    for stock in context.short_list.index:  
            order_target_percent(stock, short_weight)  

'context.long_list' and 'context.short_list' are both pandas dataframes which are indexed by the security. All you want is an iterable of the securities so use 'context.short_list.index' in the for loop. Also no need to check if the stock is in the dataframe and can't really do it like that anyway.