Back to Community
All Weather Portfolio (very simple)

A simple All Weather Portfolio with ETF and Leverage

Clone Algorithm
37
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
# --------------------------------------------------  
ASSETS = symbols('VTI', 'TLT', 'IEF', 'GLD',  'DBC')  
LEV, WT =  [1,1.5,1.5,1,1], [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):  
    for i, asset in enumerate (ASSETS):  
        if data.can_trade(asset):  
            order_target_percent(asset, LEV[i]*WT[i])  
            log.info("portfolio rebalanced")

There was a runtime error.
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)