Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
All Weather Portfolio (very simple)

A simple All Weather Portfolio with ETF and Leverage

2 responses

This is All Weather Portfolio by Ray Dalio my version, was published somewhere on this forum sometime in the past.

# -------------------------------------------------------------------------------------------------  
assets = symbols('SPY', 'TLT', 'IEF', 'GLD', 'DBC'); wt = [0.30, 0.40, 0.15, 0.075, 0.075]; M = [1]  
# -------------------------------------------------------------------------------------------------  
def initialize(context):  
     schedule_function(trade, date_rules.month_start(), time_rules.market_open(minutes = 65), True)  
     context.invested = False  

def trade(context,data):  
    if get_open_orders() or (context.invested and get_datetime().month not in M): return

    for i in range(len(assets)):  
        if data.can_trade(assets[i]):  
            order_target_percent(assets[i], wt[i])  
            context.invested = True  

Negative 6.5M cash in the original doesn't include overnight margin fees though.

Simple guard against unintended margin

def before_trading_start(context, data):  
    record(cash = context.portfolio.cash)  
    record(lvrg = context.account.leverage)