Overall Statistics
Total Trades
689
Average Win
0.25%
Average Loss
-0.09%
Compounding Annual Return
11.602%
Drawdown
14.000%
Expectancy
2.274
Net Profit
321.528%
Sharpe Ratio
1.197
Probabilistic Sharpe Ratio
71.359%
Loss Rate
12%
Win Rate
88%
Profit-Loss Ratio
2.72
Alpha
0.069
Beta
0.288
Annual Standard Deviation
0.082
Annual Variance
0.007
Information Ratio
-0.01
Tracking Error
0.147
Treynor Ratio
0.341
Total Fees
$691.36
# Dalio permanent portfolio with regular withdrawals


class AllWeatherStrategy(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2008, 1, 1)  
        self.SetEndDate(2021, 2, 4) 
        self.InitCash = 100000
        self.SetCash(self.InitCash)  
        self.MKT = self.AddEquity("SPY", Resolution.Minute).Symbol
        self.mkt = [] 

        self.etfs = [
            (self.AddEquity('SPY', Resolution.Daily).Symbol,0.3),   
            (self.AddEquity('TLT', Resolution.Daily).Symbol,0.4),   
            (self.AddEquity('IEF', Resolution.Daily).Symbol,0.15),  
            (self.AddEquity('GLD', Resolution.Daily).Symbol,0.075), 
            (self.AddEquity('VPU', Resolution.Daily).Symbol,0.075)  
            ]
        self.Schedule.On(self.DateRules.MonthStart(self.etfs[0][0]), self.TimeRules.AfterMarketOpen(self.etfs[0][0]), self.Rebalance)
        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.At(0, 0), self.Withdraw)
        self.leverage = 1
        self.buffer = 0.05
        

    def Withdraw(self):
        borrow_amount = self.Portfolio.TotalPortfolioValue * 0.0001
        current_cash = self.Portfolio.CashBook[self.AccountCurrency].Amount
        self.Portfolio.CashBook.Add(self.AccountCurrency, current_cash + borrow_amount, 1)
        
     
    def Rebalance(self):
        self.SetHoldings([PortfolioTarget(etf, target*self.leverage*(1 - self.buffer)) for etf, target in self.etfs])
        self.Plot("Custom", "Cash", self.Portfolio.Cash)
        
        
    def OnEndOfDay(self): 
        mkt_price = self.Securities[self.MKT].Close
        self.mkt.append(mkt_price)
        mkt_perf = self.InitCash * self.mkt[-1] / self.mkt[0] 
        self.Plot('Strategy Equity', self.MKT, mkt_perf)     
        
        account_leverage = self.Portfolio.TotalHoldingsValue / self.Portfolio.TotalPortfolioValue
        
        self.Plot('Holdings', 'leverage', round(account_leverage, 2))
        self.Plot('Holdings', 'Target Leverage', self.leverage)