Back to Community
Harry Brown's resurrection ?

I've just fix this code https://www.quantopian.com/posts/r-dot-i-p-harry-brown-wheres-my-t-shirt?r=1&b=54568cc030c5a3093d3d3aa5 to execute minute backtest.

Clone Algorithm
13
Loading...
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
import datetime
import pytz


def initialize(context):
    context.gold = sid(26807)
    context.treasuries = sid(23921)
    context.stocks = sid(22739)
    context.tbills = sid(23911)  # alternative to cash
    
    context.gold_notional = 0.0
    context.treasuries_notional = 0.0
    context.stocks_notional = 0.0
    context.tbills_notional = 0.0
        
    context.rebalance_date = None
    


def rebalance(context, data):
    total_notional = context.portfolio.cash + context.portfolio.positions_value
    position_target = 0.25 * total_notional
    
    context.gold_notional = context.portfolio.positions[context.gold].amount * data[context.gold].price
    context.treasuries_notional = context.portfolio.positions[context.treasuries].amount * data[context.treasuries].price
    context.stocks_notional = context.portfolio.positions[context.stocks].amount * data[context.stocks].price
    context.tbills_notional = context.portfolio.positions[context.tbills].amount * data[context.tbills].price
    
    gold_adjust = (position_target - context.gold_notional) / data[context.gold].price
    order(context.gold, gold_adjust)
    
    treasuries_adjust = (position_target - context.treasuries_notional) / data[context.treasuries].price
    order(context.treasuries, treasuries_adjust)
    
    stocks_adjust = (position_target - context.stocks_notional) / data[context.stocks].price
    order(context.stocks, stocks_adjust)
    
    tbills_adjust = (position_target - context.tbills_notional) / data[context.tbills].price
    order(context.tbills, tbills_adjust)
    
    context.rebalance_date = data[context.gold].datetime
    
        
    
    
    
def handle_data(context, data):
    if context.rebalance_date is None:
        rebalance(context, data)
    else:
        if data[context.gold].datetime > context.rebalance_date + datetime.timedelta(days=90):
            rebalance(context, data)
There was a runtime error.