With just a few lines of code, I have implemented Ray Dalio's All Weather Strategy.
The strategy is based on a target portfolio of weighted etfs representing different markets:
- 30% Vanguard Total Stock Market ETF (VTI)
- 40% iShares 20+ Year Treasury ETF (TLT)
- 15% iShares 7 – 10 Year Treasury ETF (IEF)
- 7.5% SPDR Gold Shares ETF (GLD)
- 7.5% PowerShares DB Commodity Index Tracking Fund (DBC)
The rules are ridiculously simple, since all there is to do is rebalancing the portfolio once a year, to the fixed target weights.
The attached backtest shows, that the strategy works quite well and with a relatively low drawdown and low interest rates, you can even use some leverage.
Feel free to comment and improve.
Anthony FJ Garner
Somewhere or other on my website you will find a python standalone interpretation of the all weather strategy. I chose, a la Dalio, to adopt some bond leverage although arguably an allocation to the long bond is leverage enough.
Google all-weather-portfolio-1928-2018. I used the T Bill rate, bond futures and total returns for the S&P 500 as extended. You will also find some arguments on my website as to why (in my opinion) rising interest rates will not screw the strategy provided it does not happen too fast (as in the Volker period).
Nice strategy.
Personally I do not favour commodities. But that is only my view. At least stocks and bonds have an obvious upwards bias. No so commodities over time.
But who am I to say....
Pangyuteng
Thanks for sharing! That beta (-0.018 !!) is pretty amazing, given the low rebalancing frequency. I think I'm going to manually implement this for my 401k for this year.
Josh M
Awesome strategy; this definitely inspired me to try something similar!
Mikko M
For anyone interested in this, it's also worth exploring other fixed portfolios. Some examples:
https://fourpillarfreedom.com/heres-how-18-different-portfolios-have-performed-since-1970/
Pangyuteng
I ran the backtest again - just to see how this strategy is holding up due to the on going global pandemic.
The strategy (monthly rebalanced) is suffering from a max 8.6% drawdown due to this corona virus triggered downward trend, much better than the market (27.6% drawdown this year if holding 100% VTI).
Louis Dwyer
Thank you for posting this!
Can you please explain the double indexing of [0][0] in the below line? I understand it runs every monthstart after market open (only triggering the re-weighting if monthCounter == 12) but why is it [0][0]? Is it because self.etfs contains multiple instruments?
self.Schedule.On(self.DateRules.MonthStart(self.etfs[0][0]),self.TimeRules.AfterMarketOpen(self.etfs[0][0]), self.Rebalance)
Additionally why do you have both these two lines inside Initialize?
self.monthCounter = 0
self.monthCounter = 1
Thanks again
Rahul Chowdhury
Hey Louis,
When we use DateRules.MonthStart(symbol), the scheduled event will fire on the first day of the month that this particular symbol is trading. self.etfs[0] returns the tuple (self.AddEquity('VTI', Resolution.Daily).Symbol, 0.3), which is a symbol and a float. Then self.etfs[0][0] returns the 1st element of that tuple, which is the symbol of "VTI". This means our scheduled event will fire on first day of each month that "VTI" is trading.
Learn more in the scheduled event documentation.
Best
Rahul
Louis Dwyer
Thank you Rahul for your great explanation
I have attempted to run live in quantconnect paper trading a version of this strategy with x2 leverage which is pasted below, it appears that two entry orders did not execute properly.
def Initialize(self): self.AddEquity('VTI', Resolution.Daily).Symbol #Vanguard Total Stock Market ETF self.AddEquity('TLT', Resolution.Daily).Symbol # iShares 20+ Year Treasury ETF (TLT) self.AddEquity('IEI', Resolution.Daily).Symbol #iShares 7 – 10 Year Treasury ETF (IEF) self.AddEquity('GLD', Resolution.Daily).Symbol #SPDR Gold Shares ETF (GLD), #SPDR Gold Shares (GLD) self.AddEquity('DBC', Resolution.Daily).Symbol # PowerShares DB Commodity Index Tracking Fund (DBC) self.Securities["VTI"].SetLeverage(2) self.Securities["TLT"].SetLeverage(2) self.Securities["IEI"].SetLeverage(2) self.Securities["GLD"].SetLeverage(2) self.Securities["DBC"].SetLeverage(2) self.SetStartDate(2005,1,1) #self.SetEndDate(2016,4,1) self.SetEndDate(datetime.today() - timedelta(1)) self.SetCash(250000) self.lastYear = -1 def OnData(self, data): if not self.Portfolio.Invested: self.SetHoldings('VTI', 0.6) self.SetHoldings('TLT', 0.7) self.SetHoldings('IEI', 0.3) self.SetHoldings('GLD', 0.15) self.SetHoldings('DBC', 0.15) #annual rebalancing if self.Time.year == self.lastYear: return self.lastYear = self.Time.year self.SetHoldings('VTI', 0.6) self.SetHoldings('TLT', 0.7) self.SetHoldings('IEI', 0.3) self.SetHoldings('GLD', 0.15) self.SetHoldings('DBC', 0.15)
from the log:
2020-03-24 04:00:00 :New Order Event: Time: 03/24/2020 04:00:00 OrderID: 1 Symbol: VTI Status: Submitted2020-03-24 04:00:00 :New Order Event: Time: 03/24/2020 04:00:00 OrderID: 2 Symbol: TLT Status: Submitted2020-03-24 04:00:00 :New Order Event: Time: 03/24/2020 04:00:00 OrderID: 3 Symbol: GLD Status: Submitted2020-03-24 04:00:00 :The order quantity for IEI cannot be calculated: the price of the security is zero.2020-03-24 04:00:00 :The order quantity for DBC cannot be calculated: the price of the security is zero.2020-03-24 04:00:00 :The order quantity for IEI cannot be calculated: the price of the security is zero.2020-03-24 04:00:00 :The order quantity for DBC cannot be calculated: the price of the security is zero.Jared Broad
Hey Louis Dwyer for live support please submit a support ticket via the left side of the IDE. We have to pull down the live logs to efficiently assist with debugging live strategies.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Michael Boguslaw
I backtested this without using leveraged (i.e. leverage = 1). The return was around 8% annually. While 11% annually sounds tempting (with leverage = 1.5), is this worth paying interest on margin? To my knowledge, margin has around a 8% interest rate.
Rahul Chowdhury
Hey Michael,
We can try to calculate when it is worth using leverage in this example. When using leverage, If the total return of your cash including interest payments is greater than the total return with no leverage, then it is worth taking on leverage. Let's calculate at what interest rates it is worth using leverage.
Margin Interest Rate = I Cash = Unborrowed Cash Holdings Margin = Borrowed Cash leveraged Returns = 11% * Cash - I * Margin un-leveraged Returns = 8% * Cash Let's assume we're using 1.5 Leverage, meaning Margin = 0.5 * Cash For what interest rates on our margin is it worth using leverage? leveraged Returns > un-leveraged Returns 11% * Cash - I * Margin > 8% * Cash >> 0.5 * Cash = Margin reduces to 11% * Cash - I * 0.5 * Cash > 8% * Cash reduces to - 0.5 * I > -3% reduces to I < 6%
Which means as long as you can get a better interest rate than 6%, it is worth using leverage in this instance,
You could expand on this by also including the interests paid from any short positions taken.
Best
Rahul
Miriam F.
The strategy seems very impressive, but I think you have to be very careful when you think of the next few years, after such a long bull market, you have to think twice about what the future bond yield will be when interest rates start to rise ...
Arthur Asenheimer
Hey Michael,
where do you have to pay 8% interest on margin? With zero interest rates in the US, interest rate on margin loans should also be low. For example, at IB it's currently 1.59% (benchmark + 1.5%) as you can see here.
Arthur Asenheimer
edit: you are right, there are indeed other brokers charging margin fees of 8% and more --> Comparison.
So if you want to use leverage regularly, it's maybe a good idea to switch to a broker with lower fees on margin loans.
Filib Uster
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!