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?
Jon Bailey
Hi all, there's been some discussion on possibly using options with this algo. I've modified the algo to also use options when out of market. you can set self.useOptions to True or False to compare. Thus far using put options as a hedge does not result in a better return, but I have not done any extensive testing to find more optimal parameters for using options.
Thoughts…
1. What is the optimal DTE for the options. Perhaps we could look at the avg time out of the market for this, or maybe it makes more sense to use a short DTE and keep rolling while we are in out of market mode.
2. When is the best time to roll? Right now I am just using 60DTE and rolling at 30.
3. What is the optimal weighting to devote to the options portion? Currently whatever is not devoted to options is devoted to the normal out holding (TMF, TLT, etc). I tested with 1%, but perhaps this is too low or too high.
4. How far out of the money should we be purchasing put options on the underlying? I tested with 20%, but perhaps it's better to be closer to ATM. I think further OTM is probably better for black swan protection as we can acquire more contracts for the money we are devoting to the options strat, but if the algo is truly good at taking us out of the market at optimal times, then being ATM might be better.
5. There are some very large drawdowns, due to having large gains in the options that are erased before the options are sold. You will see this much more if you devote a larger weighting to the options hedge. Currently the options are sold only if the algo goes back in the market, or we hit the time to exit, (it sells the options and then buys new options if the algo is still out of market). It might be a good idea to create some sort of profit taking strategy to sell the options if they have increased by some amount, or to trigger a trailing stop after they have increased by some amount.
NOTE: do not use QQQ as the underlying for the options. There is an issue with the prices starting in August 19, 2015. This will make the algo look insanely profitable, but it's really that the options prices are off by a couple orders of magnitude.
JSO 2045
Peter Guenther For 1) That is pretty clever, thank you for explaining it for me. I'm going to have a look at all of it again and try to understand as much of the code as possible. I saw that there is another discussion going on currently about people taking the In and Out strategy over from Quantopian so i might give that a read as well to try catch some more info.
For 3) I think I am going to take your advice and try it live to see if it works (as well as hopefully making some decent returns as well). The only thing i am worried about is that there is some inflationary pressure at the moment which might not translate into great returns.
Peter Guenther
Thanks for sharing this options implementation and structuring the discussion, Jon Bailey. Nice job. I also just quickly wanted to copy in Elsid Aliaj since I know that Elsid is looking for tail-risk hedging à la Taleb and your out-of-the-money put options implementation is a step into this direction. Of course, to fully implement the tail-risk hedging, the put options would need to be continuously held, i.e. during in and out regimes, but this is only a small modification. I reckon the smaller returns that we observe when holding the puts make sense, since tail-risk hedging is like an insurance and we usually need to be prepared to pay a premium for an insurance.
Jon Bailey
@peter-guenther , actually most of the code is from a tail risk hedging (Taleb) algo I was working on when I found this thread. What I found is that keeping the hedge on 100% of the time is a pretty big drag on returns, and then wham, the market tanks and there are massive returns. Basically the returns you get from the equity holdings are pretty much paying for the hedge and keeping stability of principal. You are just waiting for a market crash to cash in.
I thought, if only I could better predict when a market crash/correction were to take place. Of course this is a fools errand, but if I could come up with a way to know that it was mostly safe to be in the market without a hedge in place, I could dramatically increase the returns during the bull market years. What I invision is some sort of confidence indicator, with three levels. Above some level we are confident and the markets do no need to have any hedge in place. Below that level but above the lowest level, we are still “in” the market and long equities, but with a tail risk hedge in place. And then below some level of confidence, we are “out” of the market and moved into bonds/treasuries, along with the tail risk hedge.
At some point I plan to see if I can adapt the in_out algo to have this confidence indicator and if it even makes sense to do it, or perhaps it is just better to keep the tail risk hedge on all the time. What I do see, is that there are some periods of significant drawdown while we are still “in”. The “out” determination is not always timely. However those may be the periods where the middle confidence level comes into play.
Peter Guenther
Great ideas, Jon Bailey!
Musing a bit about options how this could be operationalized:
To specify the regime “in the market but with hedge” one could also use the percentile approach but with a larger alpha, e.g. 10 instead of 5 percent. This would mean that the hedge is put in place earlier (i.e. already for softer signs of stress) than the out decision is being made. For example, one could specify:
activate_hedge = returns_sample.iloc[-1] < np.nanpercentile(returns_sample, 10, axis=0)
and then activate the hedge if: activate_hedge[self.SIGNALS + self.pairlist].any()
In addition, one could try to use a broader set of signals for the “in with hedge” regime, e.g. including the Yen or Swiss Franc to identify safe haven moves, or additional markets to check for stress signs. I will have a look.
Carsten
@Jon Bailey found two doomsday hedges on the internet with for OTM VIX puts. Just searched but didn’t found the address. the Setup was like this:
Assuming the VIX is around 15, you would sell calls on the VIX on 20 and than buy the double amount of call on around 25 or higher with the total sum earned and spend equals 0. I think they were 60 DTE. Nothing mention how to define level the first call options. Second level was calculated by double amount op options and sell/buy equals zerro. They should expire most of the time with the vix below the sold putts to make it a cost free hedge. The risk would be if they expire with a VIX between 20 and 25. This was setup every month and the options were hold until expiration date. the total risk, was 0,25% of capital hedged on each of this 4 sets. Totally 1% risk based on capital to hedge. (In that case the risk is 25-20= 5 x number of option)
An other concept I found was to just buy very far out of the money options on the VIX. They used VIX 100 calls. They bought 60 DTE and rolled around 21 DTE. They did not mentioned the amount needed to hedge.
Aalap Sharma
I am running the V8 version and noticed it recently switched to TLT and back in December it had switched to stocks just before the tanking of stocks. I know these might be exceptions but just trying to understand and see if anyone knows why?
😊
Chak
Sector rotation, first tapering event, and seasonality contributed to algorithm buying behavior and your results.
Anthony B
Seems to be getting whipsawed back and forth at inopportune times. As long as it's providing alpha it shouldn't matter. The question does stand though if it should move into cash and/or possibly commodities instead of bonds during times of fed funds rate increases. Currently the drawdown isn't much better than nasdaq's due to the increase in treasury yields. Should get pretty interesting this year and next as the tapering begins+rate increases.
Peter Guenther
This comment has proven to be spot on, Anthony B. Thanks for sharing / the early warning!
Santa24
The strategy seems to fail in the 2022 regime where now 20y bond crashes together with the market. Then it looks like the strategy was overfit on previous regimes or the hypothesis that bond is a safe hedge does not hold up :)
Simone Pantaleoni
Santa24 The main problem why the strategy didn't took that into account, is that it never “faced” an inflation-shock situation like the current one, where expected inflation is far lower than the realized one.
During these kind of situations, nothing other than commodities outperform the market.
If you would have been backtesting the strategy during the '70s (for instance) you would have spotted this. But free to believe the overfitting reason :P :)
Rafael Trevisan
Hi all, newbie joining the thread here.
What'd the resources to read/learn on how to monitor and which metrics to keep an eye when having an algo trading live. For i.e., if I happened to have this algo running for the last couple years, what should I have looked to preventing it from trading in 2022.
If the questions is a bit off-topic in this thread I am happy to repost it in a proper thread.
By the way, very impressive work Peter Guenther!
Santa24, ingenue question here: what'd be the key pieces you look at to determine an algo is overfit or not? Just looking for learning on how to spot such things. I am coming from TradingView's Pine code, and I found myself in hot water recently due to overfitting my algos in there. I found QC while researching for this problem and I am liking a lot the platform so far.
Santa24
Rafael Trevisan i am by no means an expert, but the issue I see with the in-out approach is that it does very few trades, holding positions many days and QC has only data since 2002. Now, as pointed out correctly in the discussions, the in-out strategy performs very well 2008-2021, but then takes heavy losses because the macro-economical environment in 2022 is fundementally different from 2000-2021. As Simone Pantaleoni says: “the in-out has not seen an inflation-shock situation like the current one, where expected inflation is far lower than the realized one”. I can only think of the following remedies:
One might theorize that after the inflation shock, the in-out may start to work well again :)
Yuri Lopukhov
Rafael Trevisan IMO, this strategy works when US markets are growing and S&P500 grows as well. When markets are in decline it will not work. There is no way to tell if it will recover or not with technical analysis, because this is a political problem, not technical. If politicians will fix it somehow, it will start working again, if not, then no 🤷♂️
GEightyFour
Rafael Trevisan The general rule of thumb is to backtest on ~70-80% of all of the data you have. Then validate the results out-of-sample on the remaining ~30-20%. If it performs poorly on the out-of-sample then the algorithm is overfitting. But that's not enough. You will also need to fully understand the ins-and-outs of why the algorithm works and what could cause it to fail in the future. e.g when going “out” of market the In-And-Out goes to only bonds assuming that bonds are uncorrelated to the rest of the market and is always a safe haven, but we can see recently due to the inflation rate shock that assumption cannot hold.
Additionally I see that more and more people are interested into running this strategy ever since Quantopian shut down. But we will have to question how well this strategy will fare as more and more people are running it on scale, would Alpha in the future be exploited away or not?
Eric Pine
I dislike qc's only recent data availability. The free data available just happens to be within the biggest bull run in history. Judging strategy performance on this period is extreme overfitting. You could hold anything during this time and be profitable
I can make a variety of strategies that perform well during this time, but I would never consider running live
Santa24
Eric Pine do you think it would it be viable to track inflation and not trade the in-out if inflation ≥ lets 6%?
I was wondering, which professionals actually do trade the in-out live :)
Jack Pizza
I've been warning about bonds equities correlations since quantopian days but I guess nobody wanted to listen, or just ignored it purposely.
The way to make it semi better is add a moving average filter and a filter on the out part where it just goes into cash when rates are rising. Not sure if inflation rising means bond rates will always rise, as that is basically what you are trying to accomplish with that filter seems like no?
Peter Guenther
Overfit ... or over-fit?
As noted in this thread and in the In & Out Strategy thread, holding TLT (20+ year bonds) while being out did not work this time. Much of the work in this thread has focused on optimizing the in holdings. More work seems to be needed on the out holdings. A momentum-based selection sounds promising. The continued discussion in this thread should be able to specify a concrete approach at some point.
Has the In & Out fail us?
If we say out is hard-wired as meaning holding TLT then the answer may be yes. At least currently we are not better off than if we had remained invested in the market.
However, I was going back to the first two lines I had written on Quantopian when I introduced the In & Out Strategy back then in 2020:
Intuitively, it might be possible to generate excess returns via cleverly timed entries and exits in and out of the equity market. This algo may be a first step toward developing a strategy that derives optimal moves in an out of the market on the basis of early indicators of equity market downturns.
It seems that the original intention of the In & Out was to create a market timer. Musing a bit more about this, the in & out strategies discussed in this thread appear to have three main characteristics/components:
1. The in holdings selection
2. The out holdings selection
3. The market timer property
For the in holdings selection, several approaches have been proposed in this thread. Regarding the out holdings, these are alternative non-equity assets. As noted above, more work is needed to optimize this component.
But how did the In & Out do as a market timer telling us when to avoid equities?
Actually not that bad. I have a version (the v8) running that told me on 26 Nov 2021 to get out of equities which I did. At first it didn’t look like the best idea since equities reached new highs in Dec, but then starting with the new year it increasingly looked like a great move. Now I am waiting for the signal to tell me to get back in. (To generate the In & Out signal, I am using an approach similar to what Matthew Wang has proposed in the other In & Out thread.)
Long story short: The out holdings selection has disappointed. However, I am actually impressed by the market timer property. After the discussions on overfitting, ‘it uses too many signals’, ‘it shouldn’t react to individual signals but wait for multiple signals to fire’, and ‘with four parameters I can fit an elephant, and with five I can make him wiggle his trunk’ etc., the relative precision of the market timer is remarkable to me.
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!