Back to Community
All Weather back tested up to 2018

This was a test backtest for all-weather portfolio by inspired by Ray Dalio

Clone Algorithm
58
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
# Put any initialization logic here.  The context object will be passed to
# the other methods in your algorithm.
def initialize(context):
    context.stock = symbol('SPY')
    context.long_bond = symbol('TLT')
    context.mid_bond = symbol('IEF')
    context.gold = symbol('GLD')
    context.commodity = symbol('DBC')
    
    context.stock_position = 0.30
    context.long_bond_position = 0.40
    context.mid_bond_position = 0.15
    context.gold_position = 0.075
    context.commodity_position = 0.075
    
    context.rebalance_inteval = 365
    context.rebalance_date = 0

    context.fired = False
    

def rebalance(context, data):
    values = context.portfolio.portfolio_value
    
    order_percent(context.stock,0)
    order_percent(context.long_bond,0)
    order_percent(context.mid_bond,0)
    order_percent(context.gold,0)
    order_percent(context.commodity,0)
    
    order_target_percent(context.stock,context.stock_position)
    order_target_percent(context.long_bond, context.long_bond_position)
    order_target_percent(context.mid_bond, context.mid_bond_position)
    order_target_percent(context.gold,context.gold_position)
    order_target_percent(context.commodity, context.commodity_position)
                  
    

# Will be called on every trade event for the securities you specify. 
def handle_data(context, data):
    # Implement your algorithm logic here.

    # data[sid(X)] holds the trade event data for that security.
    # context.portfolio holds the current portfolio state.

    # Place orders with the order(SID, amount) method.

    # TODO: implement your own logic here.
    
    
    if not context.fired:
        order_target_percent(context.stock,context.stock_position)
        order_target_percent(context.long_bond, context.long_bond_position)
        order_target_percent(context.mid_bond, context.mid_bond_position)
        order_target_percent(context.gold, context.gold_position)
        order_target_percent(context.commodity, context.commodity_position)
        context.rebalance_date = get_datetime()
        log.info("build portfolio at " + str(context.rebalance_date))
        context.fired = True
    else:
        now = get_datetime()
        if (now.year > context.rebalance_date.year):
            log.info("new year arrivied:" + str(now))
            
            context.rebalance_date = now
            rebalance(context, data)
There was a runtime error.
1 response

@ Peter,
Try this simple version from my library:

# Ray Dalio All Weather portfolio

# --------------------------------------------------  
ASSETS = symbols('VTI', 'TLT', 'IEF', 'GLD',  'DBC')  
LEV, WT =  1.0, [0.30,  0.40,  0.15,  0.075,  0.075]  
# --------------------------------------------------  
def initialize(context):  
    schedule_function(trade, date_rules.month_start(), time_rules.market_open(minutes = 65))  
def trade(context, data):  
    if get_datetime().month not in [1] or get_open_orders(): return  
    for i, asset in enumerate (ASSETS):  
        if data.can_trade(asset):  
            order_target_percent(asset, LEV*WT[i])