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.

Clone Algorithm
2
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5b904cdcbd484443d240adf1
There was a runtime error.
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))  
            else:  
                order_target_percent(sec, 0)

    record(leverage = context.account.leverage)  

Much better. Thank you for your help.