# 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.4),
(self.AddEquity('TLT', Resolution.Daily).Symbol,0.3),
(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.EveryDay(self.etfs[0][0]), self.TimeRules.AfterMarketOpen(self.etfs[0][0]), self.Rebalance)
self.withdraw = 0.0003
self.leverage = 1.1
def Withdraw(self):
withdrawal_amount = self.Portfolio.TotalPortfolioValue * self.withdraw
current_cash = self.Portfolio.CashBook[self.AccountCurrency].Amount
self.Portfolio.CashBook.Add(self.AccountCurrency, current_cash - withdrawal_amount, 1)
self.Plot("Custom", "Withdrawal", withdrawal_amount)
def Rebalance(self):
self.SetHoldings([PortfolioTarget(etf, target * self.leverage * (1 - self.withdraw)) for etf, target in self.etfs])
self.Withdraw()
def OnEndOfDay(self):
self.Plot("Custom", "Cash", self.Portfolio.Cash)
account_leverage = self.Portfolio.TotalHoldingsValue / self.Portfolio.TotalPortfolioValue
self.Plot('Holdings', 'leverage', round(account_leverage, 2))