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

Hey guys, I am struggling to figure out the bug in this pretty vanilla algorithm and was wondering if someone could lend some insight. Thank you for your help.

2 responses

Try this:

def initialize(context):  
    schedule_function(trade, date_rules.month_start(), time_rules.market_close(minutes = 30))   

def trade(context,data):  
    assets = symbols('SPY', 'MDY', 'QQQ', 'SLV', 'TLT'); lev = 2.0  
    if get_open_orders(): return

    for sec in assets:  
        if data.can_trade(sec):  
            if data.current(sec, 'price') > data.history(sec, 'price', 200, '1d').mean():  
                order_target_percent(sec, lev/len(assets))  
                order_target_percent(sec, 0)

    record(leverage = context.account.leverage)  

Much better. Thank you for your help.