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?
Jack Pizza
Peter Guenther what is the latest version “In” based on? Is it still signals from sectors? Like GLD < SLV? ect. Or is it momentum based?
Because if it's a simple sector < > sector, that's dependent on some correlation which might not hold in the future such as stocks bonds currently.
JSO 2045
Peter Guenther Saw an idea related to this issue on the 'KEI strategy thread which might be relevant to your comment as well Jack Pizza
https://www.quantconnect.com/forum/discussion/11566/kei-based-strategy/p1
Instead of defaulting to TLT every time we want to get out of equities would it be perhaps a better idea to see the recent correlations of multiple potential hedges and see which is the lowest or at least which is non-positive. Or maybe just evenly divide what was previously the TLT order between a bunch of potential ones ‘BIL, SHV…' ?
JSO 2045
Do forgive me if those are obviously incorrect/dumb I'm very much a beginner in this space :)
Peter Guenther
That sounds like a valid approach, JSO 2045. Todd described something similar in the In & Out thread. Would be interesting to see a backtest using this approach.
Jack Pizza, the majority of the signals determining the market timing are not directly about correlations. Instead it is about extreme moves/returns. For more details, see my earlier posts in the In & Out thread explaining the percentile-based approach. Of course, there will always be some ‘correlation’-type of underlying assumption, no question about that. Anyway, my point above is that these assumptions worked this time and that the current comments about the In & Out do not fully reflect this since they do not pay particular attention to the underlying three components outlined above. Your point is that the assumptions may not work next time. I do not know about that one and cannot, and will never be able to, prove you right or wrong about that statement. I reckon that you have to pick a strategy that you feel comfortable with and believe in. It may not be this one and that is absolutely fine.
Peter Guenther
Further to my post above
Has the In & Out failed us?
I have argued above that the market timer property worked reasonably well in the recent market environment. In the In & Out thread, I propose that the recent overfitting claims do not appear to stand on a solid footing. First, what is mainly ‘fitted’ in the In & Out is the market timer which is also the algo’s main purpose. Second, the recent under-performance is the result of the out holdings which do not seem to have been fitted much since they were largely neglected in the discussion. So, underfitting or lack of fitting instead of overfitting seems to be the issue with this component.
Attached is a chart to substantiate my point that the market timer has worked reasonably well. These are live trading return results from my Interactive Brokers account in which I use the market timer property of the In & Out to trade a selection of equities when I am in and alternative holdings when I am out. What now turned out to be quite useful to visually illustrate the performance of the market timer: I have set cash as the out holdings and only recently added bonds (20%) to the mix, which means that we generally see a flat line when the algo went out. I have been using the In & Out market timer for my trading since my first post on Quantopian in Oct 2020, so for almost two years now, having moved to the latest algo versions around about the same time that I have posted them in the In & Out thread. By no means this is meant to say that you should do the same or that the market timer will work in all future situations. However, it can provide a deeper insight into the different components that are at work in an in & out algo and underline the importance that we need to be clear as to which component’s performance we are referring to in our comments and claims.
Santa24
Peter Guenther great post thanks! so it seems that in practice the IN holdings should be a portfolio mix of ETFs that create execess returns over the market. I assumed the remedy was to set the OUT holdings to Cash if the inflation is significantly rising. Do you have an additional portfolio selection logic for the IN holdings in place to create excess returns?
Peter Guenther
Appreciated, Santa24. Regarding the out holdings, it’s still on my list to formalize this a bit more and share an update. Just too short of time lately but hopefully at some point. This may sound more mysterious that it actually is: The logic for the in holdings I currently cannot publish due to an agreement. Again, maybe at some point. When the Alpha Market was still on, it was a bit easier to share without directly posting the code: I had an alpha there called the InOut G-Force which used the logic. It's a selection of stocks not ETFs. There might be a new chance when the revamped Alpha Market will go live. Of course, there are also alternative stock selection logics that have been developed in this thread.
Jack Pizza
Peter Guenther a momentum based approached for out 1,3,6,12 month on QLD, IEF, BIL works fairly well. With weights 12,4,2,1.
It's been backtested almost 100 years in a paper Vigilant Asset Allocation and as an out works great, assuming you have proper in / out signals.
Peter Guenther
Thanks for sharing, Jack Pizza, including the paper title. That does sounds sophisticated. Looking forward to play around with that idea and to test a few constellations.
Peter Guenther
Not as sophisticated as Jack Pizza's suggestion: I am currently experimenting with a simple switch for the out holdings from TLT to cash if TLT's return is negative.
During the recent TLT meltdown, the attached algo holds cash from the end of Jan onwards and can reduce the drawdown to about -15%. Still not a small drawdown. A stop loss and waiting period might be an interesting addition, although it would of course deviate from a plain momentum-based approach. Alternatively, one could try to get ahead of the bonds meltdown by predicting it through appropriate early signals.
The new bits in the attached algo:
- Line 34: lookback period for testing the TLT return
- Line 134: calling the function to test the return
- Lines 160-182: the actual function. A bit wordy in order to catch potential data issues
PS: Also consider Jack's suggestion regarding holding a basket of multiple alternative assets and using multiple weighted lookback periods.
Jack Pizza
Peter Guenther check the other in and out thread i posted a lot of stuff there, stop loss, moving average, and a backtest with a lot of momentum based code, but this looks good.
I'll trying adding momentum soon.
Jack Pizza
Peter Guenther I've added momentum stuff to the algo stuck at self.trade take a look, you'd know better how to convert the arrays into dictionaries keys or whatever trade is doing.
I tried with straight up set holdings, but performance degraded so whatever trade is doing with the weights stuff, such as don't trade unless changes ect seems to be needed.
Code is attached
Peter Guenther
Thanks for that, Jack Pizza, I will have a look.
I have also tried another idea. Backtest attached.
For the out holdings, we do not consider TLT vs cash but TLT versus its inverse. Now, I wanted to use TBF (1 x inverse TLT) but ran into an error ("key not found" at some point) which I still have to figure out. So, the attached version uses TBT instead (the 2 x inverse TLT).
I still have to analyze the result in more detail but I thought I'd share directly so that others can have a look as well if interested.
Jack Pizza
Can probably backtest by continuing to use cash still just maybe if cash wins, you just short TLT. Would have to due a risk assessment on that inverse TLT fund, as they can blow up, like all the VIX OIL funds did.
But that looks like a great idea
Peter Guenther
Good thinking, Jack Pizza. I tried using a short in TLT. In the attached backtest, I could only use a -0.5 weight for the short due to buying power issues. However, even then, the total return suffers and the drawdown goes up due to a substantial underperformance during 2008/9. So, it seems like we have to dismiss the short idea. Not a problem, back to the drawing board.
Lex Nox
Hi to everyone, it's really an interesting thread; I would like to implement the version of the algorithm with the universe of stocks instead QQQ, can you suggest me the lasted code to start? In my opinion we could use relative momentum for the Out alternative instruments (to select instruments for example in a basket of bonds ETFs and commodities ETFs)
Peter Guenther
Welcome to the team, Lex Nox.
There might not be a simple answer to your question since there are different stock selection strategies that we have discussed in the thread, each with their own latest version 😊. I have tried to label the strategies in earlier posts: ValuationRockets (earlier: EarningsRockets), QualUp (Quality Companies in an Uptrend) and F-Score (Piotrosky F-score).
I think that you find the latest versions for most if not all of the strategies on page 2 of this thread. Hope this helps. Your idea sounds definitely interesting.
Santa24
I like to share another hypothesis driven approach I explored to not run into the bond draw down in 2022.
I assume that the difference between the 20y and 30y bond yields should be very stable over time. So i added an anomaly tracker with 2-3 year rolling window with the yield_differences (yield30-yield20). If the percentile of the current yield difference value is very low (like 0.5/100 percentile) we add a 14 day blocking period where the bonds are set to weight=0.
In addition, I think that after QC updated the warmup functions, one probably does not need the ObjectStore to cache OS_signal_dens anymore in LiveMode. The warmup will every day call the scheduled self.History and re-build the signal dataframe, so loading it from cache should be necessary anymore.
This yield anomaly approach produces kind of the same result, but might be also in robust into the future? We might not want to trade bonds if the yields behave in very anomalous ways :)
Peter Guenther looking forward to your feedback. Are you on the discord channel by any chance?
Jack Pizza
Santa24 are you measuring if yields are inverted? Either way the simple return momentum calculation between cash vs 30 year would suffice as if cash return > than 30 year something has broken.
Jack Pizza
Also how can we backtest this 100 years? I have an excel file for bonds stock returns that goes back that people used to backtest dual momentum strategies, but not sure how we can get sector data going back that far.
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!