I am trying to implement the following momentum strategy, with the following rebalancing routine:
- From three ETFs representing US, EU and Emerging Markets, select the one with the highest momentum
- if the momentum of this ETF is higher than the momentum of a treasury bills etf, invest everything in this ETF
- else, invest everything in a bond ETF
def Rebalance(self):
self.symbolObjects.sort(key=lambda symbolObject: symbolObject.Momentum.Current.Value, reverse=True)
currentLong = self.symbolObjects[0].Symbol
if self.symbolObjects[0].Momentum.Current.Value < self.tBill.Momentum.Current.Value:
currentLong = self.bonds
self.SetHoldings(currentLong, self.leverage, True)
The attached backtest shows, that my implementation does not work as intended.
Why is the US-etf sold 2 consecutive times? Why is there no position after July 2010?
Vladimir
Filib Uster
The problem is not with the code, but with the symbols you are trying to use.
In the QC database there are no such symbols: IUSA, IQQY, ENUM, IBCC.
AGGG: start trading Jan 25, 2020
Try this:
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.
Filib Uster
Much better, thanks.
However, as European Retail Trader, I cannot buy most of the US-ETFs and need a UCIT-surrogat for each of the ETFs you use in your code. Is there a reason, why UCIT-etfs such as the ones I tried to use are not included in the QC - database?
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.
Derek Melchin
Hi Filib,
We offer all data from US main exchanges. The reason we don't have some data may be:
If UCIT ETFs meet this criteria, we don't support it.
Best,
Derek Melchin
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.
PokerWinner
Hi Derek,
Do you plan on adding European securities at some point?
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.
Jared Broad
Hi Pietro,
Yes eventually. For now, we're focused on stabilizing the features we have and improving documentation and tools for people to use the platform. Realistically I think it will not be in Q2 or Q3 though as the market of users interested is small relative to the US markets and its expensive data to add to the platform.
Best,
Jared
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.
AleNoc
It could be interesting implement UCITs ETF also paying an addon if necessary (EUREX, Xetra, ETFplus), otherwise in Europe the platforn is less usefull. I hope you will implement this functionality soon.
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.
AleNoc
Also EURONEXT and London Stock Exchange UCITs ETFs could be usefull
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.
Alexandre Catarino
Hi Lex Nox
Thank you for your patience.
QuantConnect has launched a WeFunder campaign to give the community more control over the priorities to implement new features such as supporting new brokerages or a security type such as European Equities.
Best regards,
Alex
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.
Mark hatlan
Yes, when SPY's closing price is less than the 200 Simple Moving Average sell all Leveraged ETFs (if long) and go to cash. The code I put went to plain cash when SPY<200SMA down in the "Else:" line.
You could go to SHY, IEF, TLT or AGG, or any combination of those to move into risk off positioning for example. The point is to have a bull/bear market timer to get you to a risk off position to preserve capital. Once the market changes, you can back to a full risk on position. This is where the 3x leverage will give you good alpha over time.
As for the market timer logic it doesn't have to be SPY<200SMA. There are lots of ways to determine a bull/bear cycle. If the 6 month percent return is less than 0%, the number of down days over the last few months is greater than the up days, etc. Look for some white papers that include market timer logic for more examples.
I'm a trader tying to learn to code, so I hacked this together, I'm not 100% certain this code is error free ;)
The 2 week rebalance is not as critical in Taylor's version, instead it keeps the allocation consistent. But when there is a market timer involved the rebalancing schedule becomes critical. If you were to only rebalance every Jan. 1, then you will get out of bear markets too late and get in bull markets too late, so you may not achieve any alpha. Daily rebalancing is too often in this case. However when you switch to weekly, bi-weekly, or even monthly, then you get in that sweet spot to get out of a bear market in time and get in a bull market early enough to capture those gains.
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.
Jack Pizza
You guys might find this interesting similiar idea without all the 3X for potentially issues.
https://www.quantopian.com/posts/new-strategy-in-and-outThe 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.
Derek Melchin
Hi Elsid,
Thanks for sharing. Since Quantopian is shutting down, users can proceed to this thread instead.
Best,
Derek Melchin
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.
Mark hatlan
Thanks. I'll check the in and out thread.
Also after looking at the above backtests I found that TVIX is not bought until the last few years, there may be a data problem.
So I've put this together with futures (a simple version without complex rolling code that is out of my skill for now). This allows the /VX to be used instead of TVIX. Interesting thing is that the futures version doesn't perform as well as just the plain TQQQ/TMF 50/50 model.
I've even tried using TQQQ/TMF with /VX to help with volatility, and it doesn't help either long or short /VX.
After looking at this original strategy more closely I take back my original comment about a risk off signal being needed, I do think that this strategy is hedged enough to not need a long volatility or a go to cash signal.
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.
Samuel Schoening
mark hatlan this is something I have found on previous renditions of this strategy. It is not buying TVIX or what is now UVXY because the data is not split adjusted. Therefore the price of those is over 1 billion dollars a share upon their inception lol. Also rip everyone using TLT and thinking that GLD was an inflation hedge. Last few months were absolutely brutal.
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.
Samuel Schoening
mark hatlan Feel free to check out my own exploration of this passive rebalancing concpet using the following hedges: SCO -2x oil, GLD (as inflation hedge *theoretically :( 2021), and TMF (3x long term treasuries). As equities we have QQQ, SPY, and IWM. It is a great plan long term but inflation poses biggest risk. I recommend a swap to UVXY or simply cash if you believe a high degree of inflation is coming.
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.
Mark hatlan
Yeah gold has been quite a ride the last 20 years. The recent commentary around how gold is not the inflation hedge it once used to be remains to be seen, at least if we ignore the last year and look ahead 10 years. If gold has truly changed its inflation correlation, then there has to be something large money managers are using to replace it. I haven't looked so I don't know what that could be.
Its interesting you have inverse oil in there, I haven't looked at that before as a hedge.
But why do you have SPY, QQQ and IWM? wouldn't it be simpler to have just 1? even if it was the one with the strongest upward trend.
Here is another example on stock and bond hedging using the last 100 days standard deviation, and using that as a timer to either be 100% in TQQQ or reduce TQQQ allocation and hedge with bonds. Really there are countless ways of putting in some sort of timer to hedge, I've only explored a handful.
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.
Mark Reeve
@Mark Hatlan, Be careful with your use of STD - I believe what you want to compare is the STD of RETURNS not the STD of Prices. Obvisouly comparing STD of prices is pointless as the STD of a higher priced stock will almost certainly be higher - irrespective of their respective volatilities (of returns).
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.
Mark hatlan
Yes you are right in that a straight comparison of STD between two differently priced data sets is not apples to apples. STD of the % return is certainly a good way of doing that. Do you have an example of this we could look at with this strategy? Seeing that code would be a great help to us lesser experienced with python.
My example above was not a normalized method of comparing STD, but just an example that if one wants to switch the allocation around with this portfolio with a bull/bear trigger there are unlimited ways of doing so, perhaps STD in some way can help improve this strategy generally as opposed to a static 50/50 or other ratio.
It would also be helpful if someone with better coding experience than myself could take a stab at using /VX futures for the long volatility hedge, it may prove better than the TVIX and VXX that have astronomical historical pricing in the backtests.
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.
Derek Melchin
Hi Mark,
To get the STD of historical returns, we can use IndicatorExtensions.
IndicatorExtensions.Of(StandardDeviation(100), self.ROC("QQQ", 100, Resolution.Daily))
We just need to ensure we increase our warmup period to accommodate.
self.SetWarmUp(200, Resolution.Daily)
See the attached backtest for reference.
For an example adding the VIX futures index, refer to this related thread.
Best,
Derek Melchin
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.
Mark hatlan
Thanks Derek, I didn't know about the indicator extentions. I'll check out the VIX thread too.
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!