Intro
Superior algo returns can be thought of as being the result of two components: a great strategy regarding ‘what stocks to buy’ (the stock selection component, SEL) and a ‘clever timing’ (the in & out component, I/O) regarding when we are ‘in’ the market and hold the stocks versus when we are ‘out’ of the market and hold alternative assets such as bonds. We often focus on optimizing SEL and tend to neglect I/O; thus, for an important discussion of recent I/O tactics, see here.
Focus of this thread: Optimal SEL + I/O combinations
It is worthwhile to separately optimize SEL and I/O. However, the ultimate total return will also be determined by a certain synergy or dissonance between the two components. So, it seems that we won’t get around the arduous task of individually testing (all possible) combinations to identify optimal SEL + I/O pairs, which is the eventual focus of this thread. I reckon a preparatory step can be to dig up all the hidden SEL and I/O treasures from this forum and beyond to see what inputs are available for the combinations.
Ultimate objective
Let's get rich together, why not?
Peter Guenther
gpw radar: Futures are a good idea and are likely to improve performance. Tentor (see In & Out thread and Quantopian archive) used futures on Quantopian and could improve the algo's total returns. However, see the discussion in the In & Out thread regarding that implementing this futures strategy is very tricky on QC.
Nathan Swenson: Great point. Probably we need a code snippet forcing the sell orders to be executed first, i.e. for those stocks whose weights are positive in the current holdings but zero in the new holdings. Then, ideally, the algo would wait for a complete sell confirmation before it goes on to the purchases. Currently beyond my coding skills to implement this -- I only can say that you made a great point there and I am hoping that others might have a suitable code to implement the idea :)
Nathan Swenson
Regarding the warm up necessity, we will know once the next IN signal comes. I currently have the WarmUp line commented out, but haven't Peter's edit to avoid immediate entry at start. I will compare my live version to the backtest to verify it's correct. I'm currently in TMF from 34.10 (current price 36.24).as compared to Algo's entry of 37.06 on 10/6/2020 as noted in backtest log. I was lucky with my entry, catching the bottow (so far). This will give me some cushion once I make the switch into TQQQ.
Aalap Sharma
Nathan Swenson did you deploy it on the quantconnect paper trading platform and did you get a error due to large warmup period? I deployed it on Friday after close and havent seen any errors yet. I guess it will happen tomorrow once the market opens.
I also added a snippet to email alerts to a google group, lets see if that works.
Nathan Swenson
Aalap Sharma,
I have the warm up declaration commented out on the version I'm running. I haven't tried the latest version, but was necessary to comment out on prior version for it to run.
I am running it live with paper trading and just use signals to manually trade my accounts.
Peter Guenther
Aalap Sharma and Nathan Swenson: Great discussions about implementing this for live trading, keep it going and good luck with the investments :)
Just to continue with the test series, I was running a different stock selection that Joseph Kravets mentioned: a momentum stock selection (via the MTUM ETF). Attached are the findings. My feeling is that the In & Out may not combine that well with a momentum strategy, but of course more tests are needed to fully assess this.
SEL[“MTUM”] + I/O[“In & Out”]
Total return: 368%
Peter Guenther
And a disruptive innovation selection that Joseph Kravets has suggested. I reckon with this and the MTUM above, we have to factor in that these ETFs were started past 2008, which is 'depressing' returns in the backtests. Later, I will try to post a comparison with QQQ for comparable timeframes ... and then a question also is how we think the future will look like (vs how the past looked like = backtest results).
SEL[“ARKK”] + I/O[“In & Out”]
Total return: 543%
Peter Guenther
Quite interesting! To benchmark the prior two posts:
MTUM: It seems that MTUM started in April 2013. From 1 Apr 2013, the SEL[“QQQ”] + I/O[“In & Out”] generated 213%. Thus, the 368% return of the SEL[“MTUM”] + I/O[“In & Out”] combo outperforms. Forget what I said above regarding the In & Out not combining well with a momentum stock selection strategy. This finding is more in line with what Jonathon Tzu wrote in the "Quality Companies in an Uptrend" thread:
<<Peter Guenther I've actually found that the In and Out Strategy from Quantopian meshed very well with returns (nearly tripling returns over 18 years, the length of the backtest).>>
ARKK: The ETF seems to start in Nov 2014. From 1 Nov 2014, the SEL[“QQQ”] + I/O[“In & Out”] generated 172%. Thus, the 543% of the SEL[“ARKK”] + I/O[“In & Out”] combo clearly outperforms.
It seems like we have to reshuffle our portfolios again. Kudos, Joseph Kravets for the tip :)
Nathan Swenson
Peter, that's great! Now if we could improve "Out" holdings. The largest draw downs are in Bonds at least for my aggressive setup with TQQQ and TMF. There I see a 49.9% draw down. Not so easy to overcome that other than using a less aggressive funds and sprinkle in some Gold.
Joseph Kravets
@Peter Guenther In my view you could select between arkk, mtum, and a quality and value etf to see which style is best that year. Arkk is what i would call a "yolo etf" , like what people on wall street bets would buy. maybe in the future value outperms momentum, who knows. You can do a portofolio optimization between the different factor etfs. Also just holding bonds is simplistic, you can have another strategy that outperforms in bear markets, such as trend following currencies/commodities/forex/maybe crypto. trend following does best in bear markets and always adapts. we dont know that bonds will do well if interest rates go up.
Joseph Kravets
I use breakouts on 40 different futures markets. it did very well during the covid crash. you can combine this with the in and out but its complex.
https://qoppac.blogspot.com/2016/05/a-simple-breakout-trading-rule.html
Pcnpj
Ah, nevermind. Seems like trading economics was discontinued.
Goldie Yalamanchi
Vladimir
So I have renamed the filters as Fundamental and Momentum filters and I believe I did have them in the order you suggested. Momentum then fundamentals.
self.AddUniverse(self.MomentumSelectionFunction, self.FundamentalSelectionFunction)
Anyways I have added a short backtest here one more time to go thru the code. Yes I don't understand that initial TLT symbol error either. I may need some help to clean up this code (I did remove some more unused items). Yes I think your mention of the leverage it sometimes exceeds 1.0 and gets as high as 1.2 and in the beginning maybe for that reason it has a 20% drawdown in Sept-Oct.
Goldie Yalamanchi
Vladimir
So I have renamed the filters as Fundamental and Momentum filters and I believe I did have them in the order you suggested. Momentum then fundamentals.
self.AddUniverse(self.MomentumSelectionFunction, self.FundamentalSelectionFunction)
Anyways I have added a short backtest here one more time to go thru the code. Yes I don't understand that initial TLT symbol error either. I may need some help to clean up this code (I did remove some more unused items). Yes I think your mention of the leverage it sometimes exceeds 1.0 and gets as high as 1.2 and in the beginning maybe for that reason it has a 20% drawdown in Sept-Oct.
Peter Guenther
A quick one to share: I reimplemented an earlier 'for fun' algo (here in a leveraged version) that capitalizes on the strong run up in the silver price after significant market drops. The play (particularly lines 127-135): after the market has dropped by 30% or more and when the In & Out says 'in', we invest in double leveraged sliver (AGQ) until the market has approx. (within 1.5%) recovered to its pre-drop level. So here it is: the In & Out with a silver fountain :)
SEL["TQQQ" VS "AGQ"] + I/O["In & Out"]
76,000%+
Radu Spineanu
Nathan Swenson Trying to deploy it with paper trading as well and running into "Runtime Error: Execution Security Error: Memory Usage Maxed Out - 512MB max, with last sample of 1049MB." Which plan are you using? Or what are some tricks tot make it more efficient?
Vladimir
Goldie Yalamanchi,
Sorry, I just now realised that Peter Guenther changed his definition of superior stock selection to leveraged ETF.
I have published your strategy here.
Peter Guenther
Goldie Yalamanchi and Vladimir: happy for you to add the Qual-Up conversation here if that would be of interest. True, we branched off a bit into the area of leverage. But the main question still is which stocks to select and combine with which in & out tactic. Leverage is just a multiplier of these choices, really. The key is that the underlying SEL + I/O choice is solid.
Goldie Yalamanchi
Thanks Peter Guenther for the confirmation. Yes as you may know, I have been trying to run this against real $$$ as may be others. I do have concerns about all the concentration of SEL into tech stocks -- I just don't know if that bubble will continue so I thought in another basket let me try to use the Qual-Up strategy presented on this forum as a hybrid. Yes, due to the very nature of the IN/OUT even the Qual-Up SEL stocks do very well.
That said, one thought is that sometimes, IN/OUT is a bit early (Feb 2020 pre-Covid) or very late (Aug 2018 - Nov 2018). The latter one there is like a 25% drawdown (depending on the leverage instrument or SEL) is a bit harsh.
Can anything be done to improve that -- I know if we overly tune the shifts of the indicator pairs instruments noise may be introduced and the algo may not work well. But just considering somehow to improve that without "overfitting".
Someone suggested some other thoughts, I have added a few in the list.
Guy Fleury
@Peter, great work. You must know that you can push your trading strategy much higher. Changed a few things, but mostly raised the initial capital to $1M and raised the leverage to 1.2x. Not excessive, but nonetheless, productive. Added leveraging expenses would be more than covered by the added profits. The following chart does suggest that it can be done.
You could push a little more, and more than double or triple the outcome. It is a matter of choice and risk tolerance. Regardless, seeking more volatility by using leveraged ETFs will bring slightly higher drawdowns. However, knowing that they will be there, using this leveraging will force us to design better and more sensitive protective measures and better switching procedures.
Peter Guenther
Guy Fleury: Holy Guacamole, thanks for sharing! :)
Peter Guenther
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!