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?
Leandro Maia
Peter,
in the attached version I removed the history call from calc_return and added a standard ROC indicator added by OnSecuritiesChanged. This change didn't alter the performance, but I did two other that did:
1. Universe resolution change to minutes to avoid stalled prices. Small performance reduction
2. Universe selection performed every month start. In your orginal version universe is selected one day after rebalance but then is only and the next in signal is triggered which could mean months and the selection becomes to alleatory. This resulted however in some performance degradation.
Thunder Chicken
Question. Is there a way to just limit the results to securities in NDX, SPX, etc. Basically to only trade the QQQ constituents?
Thank you!
UK Bilgi Servisi
Just seems too good to be true. 50-60% annual compounding rate.. There should be something wrong here, either in the code or there is overfitting.
Peter Guenther
Leandro Maia: This is pure coding magic, very nice work there! The changes all make a lot of sense, so this code should definitely be the basis for further work on the Earnings Rockets with In & Out. I reckon the only thing one could check is whether there is any benefit in performing a slower universe update (e.g. bi-monthly or every quarter). I mean, the backtest performance is impressive anyway.
Thunder Chicken: I know that there is a universe called QC-500 that mimics the S&P500 firms (documentation). I am not aware of a QQQ universe, but it might be something that may be coming at some point (?).
UK Bilgi Servisi: Overfitting may always be a concern with an algo that has more than say 3 or 4 parameters. Parameter sensitivity analyses can give an indication. For the 50-60% you refer to, these are algos trading 3 x leveraged ETFs. This is a furious bull ride and when the future does not play out like the past, leverage aggravates the problem. If the model is overfitted, and the kind of overfitting turns out to be a problem, then unleveraged trading is safer.
Thunder Chicken
Peter Guenther - Sorry for an confusion. What I was saying, in respect to Earnings Rocket with In & Out, is there a way to limit the UniverseCoarseFilter(self, coarse) and only return stocks by sector (technology, healthcare, financials etc.,) or by which Index they are consitituents of, say just constituents which are part of the NASDAQ-100, S & P 500, or Russell 2000.
Thank you!
Peter Guenther
Attached is a backtest for the Earnings Rockets with The Distilled Bear in & out algo. The total return is below the combo with the In & Out. However, there seems to be an issue of uninvested cash from Jul 2020 to now, looking like 7-10% of the total wealth are not invested which certainly drags on performance. It’s also interesting that the max drawdown (27.5%) is above the In & Out combo's (21.8%), since The Distilled Bear has a smaller drawdown when the SPY or QQQ are traded as the stock selection (compare in the In & Out thread). If you spot a coding-related explanation, give me a shout or post an update; I will also go through it again.
SEL[Earnings Rockets] + I/O[The Distilled Bear]
Total return: 2383%
Sharpe ratio: 1.35; Max drawdown: 27.5%; Compounding annual return: 28.0
Peter Guenther
Thunder Chicken: What you could do is to use the Morningstar sectors, for instance by adding an appropriate condition to the CoarseFilter.
https://www.quantconnect.com/docs/data-library/fundamentalsFor the sectors, see here:
Ctrl + F for "Asset Classification". For instance, MorningstarSectorCode.Technology can give you the technology sector. For a more fine grained classification, you could drill down to the industry group level or industry level. The latter gives you specific industries such as Semiconductors, Solar, Biotechnology etc., so quite a detailed level for your selection.
Hope this helps / provides you with a starting point!
Thunder Chicken
Peter Guenther - Thank you for sending this over. I am looking at it now.
-TC
Simone Pantaleoni
Hi folks!
Here it is my contribution: adjusted CoarseSelection using weekly average volume based sorting (since I think the daily volume doesn't make any sense at all - :P )
16.1% drawdown - 4377% TR
Peter Guenther
Nice work there, Simone Pantaleoni , thanks for sharing! I haven’t had a chance to have a detailed look; anyway, the algo looks very promising. Not sure whether you had a chance to check out Leandro Maia ’s point regarding the universe selection being performed one day after rebalance (= one day too late)? Irrespectively, I think that your algo gives the strategy a nice boost.
Thunder Chicken
Peter Guenther - One thing that would be nice to see is the original Momentum Strategy with the distilled bear. I say such because the original momentum strategy rebalnced the stock portfolio on a monthly basis. The current version of earnings rockets doesn't seem to do so.
https://www.quantconnect.com/forum/discussion/3377/momentum-strategy-with-market-cap-and-ev-ebitda/p1 .
I've been working on it for a bit but can't seem to reconcile the logic.
Another way to say it would be, the SEL[Earnings Rockets] + I/O[The Distilled Bear] rebalancing monthly, when in market (i.e. owning stocks), but taking no rebalancing action when the I/O flag indicates bonds (i.e. owning TLT IEF etc)
Damiano Bolzoni
Thunder Chicken I was working on the monthly rebalacing too....in 2020 the strategy doesn't buy any other stock after April and it sticks to the same ones forever...
Leandro Maia
In the code I posted above, if you un-comment the lines below, you'll get a rebalance every 20 days, or you can change it to whatever number of days you like.
#if self.be_in and self.reb_count > 0 and (self.dcount - self.reb_count) == 20: # self.rebalance() # self.reb_count = self.dcountThunder Chicken
Damiano Bolzoni - I am experiencing the same issue and attempting to identify the problem.
Damiano Bolzoni
Thunder Chicken this is what is causing the issue:
# Only re-shuffle stock allocation when switching from out to in, not in-between
if not self.be_in_prior and self.be_in:
self.flip_flag = 1
self.rebalance()
self.flip_flag = 0
and
def UniverseCoarseFilter(self, coarse):
if (self.rebalance_flag or self.first_month_trade_flag) and (self.be_in or self.flip_flag):
(there is a similar check in the "UniverseFundamentalsFilter" function)
Because rebalance() sets the rebalance_flag back to 1, which in turns allows the filter functions to recalculate, no stock return is ever recalculated. On top of that, rebalance() is only called during the in-out switch...
I'm sure it si possible to clean up and "smil down" all these variables that are used to trigger the filter and the rebalance functions...but for now I just managed to trigger a refresh of the stocks after April 2020...I'm now testing the whole 2008-2020 period...
Damiano Bolzoni
Sorry Leandro Maia I missed your early post(s). Thanks for fixing the rebalancing and for the clode cleanup :-)
Goldie Yalamanchi
Yes I am sorry I think I may have introduced that self flip_flag code.
Also, there is another version here I have shared here that includes the Momentum + EV/Ebitda version to make sure to do at least one rebalance a month. I think Leandro Maia code does that when you uncomment those lines per my testing.
Additionally, the first ever trade is taking about a month (or in this case 20 days) to initially happen. I think some code has to be added in the beginning of the rebalance logic that if initially - Day 1 not in the market then get into the market! (as long as self.be_in or whatever flag is true or non-zero).
My rebalance when out of the market had this code in there, to initially make it trade and not wait as long as self.be_in was non-zero. I will just include the code snippet to not step on anyone's toes:
Goldie Yalamanchi
def rebalance_when_out_of_the_market(self):
if self.be_in == 999:
self.flip_flag = 1
self.rebalance()
self.flip_flag = 0
Thunder Chicken
Goldie Yalamanchi - What was the below regarding?
def rebalance_when_out_of_the_market(self):
if self.be_in == 999:
self.flip_flag = 1
self.rebalance()
self.flip_flag = 0
Thunder Chicken
Peter Guenther - Just wondering if you figured out the leverage issue with SEL[Earnings Rockets] + I/O[The Distilled Bear]?
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!