This thread is meant to continue the development of the In & Out strategy started on Quantopian. The first challenge for us will probalbly be to translate our ideas to QC code.
I'll start by attaching the version Bob Bob kindly translated on Vladimir's request.
Vladimir:
About your key error, did you also initialize UUP like this?
self.UUP = self.AddEquity('UUP', res).Symbol
Santa24
Narendra Kulkarni i didnt trade the SPY instead of QQQ, i changed the self.MRKT signal from QQQ to SPY that is used to calculate the outlier percentile return vectors for the In/Out signal
Guy Fleury
@Santa24, using SPY as signal generator should not be a better alternative to QQQ, again by construction.
SPY is averaging over 500 stocks while QQQ is doing the same on the highest 100.
The result: SPY's price movement is less volatile as can be seen in the provided chart above. This will have for average effect to delay trading signals. The other 400 SPY stocks lower SPY's average performance compared to QQQ. It also dampens average price movements also as shown in the above chart.
Trading implies exploiting price variations. The lower the average price variations, the lower the average profit potential.
Bill Dawson
strategy? I'm new to this and woud like to be able to follow the story from
the beginning. Thanks
Guy Fleury
Quantopian archives can be found here.
Tristan F
In/out with relative momentum attached. This combines the in/out trigger with Bold Asset Allocation relative momentum (Bold Asset Allocation (BAA) - Keller by Tristan F - QuantConnect.com). The relative momentum is likely suboptimal. For example, it uses end of month values to determine the SMA, which doesn't make sense for a strategy that can trigger on a daily basis.
The offensive (in) and defensive (out) asset universes both have cash (as BIL), and the offensive includes consumer staples (XLP), which is a good diversifier to QQQ. Results are not as stellar as just QQQ and TLT up to 2021; but the relative momentum and diversification of cash and consumer staples avoids the 30% drawdown in 2022.
If you chose to build on this, please share any improvements.
Jack Pizza
Tristan F this is a better way than some of the other modifications of adding momentum, question is how can we add an SMA filter to trading in? It seems the trading logic is lumped for both in / out with the weights logic.
Not sure if it would effect performance or not, but from my prior testing it helped a bit with drawdowns, even though Gary Antonacci says there is no need for a MA as price momentum itself is basically the MA, I've found that it skews risk a bit when adding an MA filter to trading long.
Lastly I guess the debate is why is in / out better at squeezing performance than just straight dual momentum type of strategies, and how can we backtest this say 100 years to really check it's robustness, or if it's just overfitted the last 10-20 years. I haven't been able to really find any research papers on extreme price moves and their accuracy. It does make sense as a hypothesis of an extreme move meaning something broke and caution.
Narendra Kulkarni
Guy Fleury , I believe you are incorrect about the differences between SPY and QQQ. https://www.invesco.com/us/financial-products/etfs/holdings?audienceType=Investor&ticker=QQQ
QQQ is not simply the top 100 companies. Its taking a more concentrated position in tech. SPY by construction is more diversified. It contains 500 largest companies. NASDAQ by construction ignores banks and energy companies. I know that last 12 years have great for tech, but there is no fundamental reason to believe that tech will always do better in the future. SPY is more diversified and therefore I would argue that its safer investment to hold. But if you do chose QQQ do this with your eyes wide open and understand the risks.
Other arguement that you have made is that since SPY has 400 more smaller market cap stocks therefore it will always underperform. This is patently false. Just because a company has a lower market cap does not imply it will have lower growth. In fact I would argue that smaller companies are more likelier to grow.
But I will accept that by construction QQQ is more likely to have higher volatility. But I am not totally sure that QQQ vs TLT is a better bet to make than SPY vs TLT. I know that backtest will show that QQQ does great but I will argue thats its just luck and not by construction.
Jack Pizza
Tristan F also says defensive momentum is set to 12 months, but self.TD shows 1? is it set to 1 month or 12? Trying to figure out why your version goes into TLT during 2022, whereas the last version i posted stays in BIL and goes into QQQ for one day or so.
Tristan F
Jack Pizza ,
I'm not sure I understand. Are you suggesting determining momentum using a low pass filter (fast SMA) instead of the latest price? For example, check that the average of the last 2 weeks is trending higher over the last 6 monhts: SMA(10) / SMA (126), instead of the last price P(-1)/SMA(126)?
The paper from Keller (here: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4166845) has all the definitions. LO is lookback on offensive, and LD on defensive (6 and 12 months respectively in what was shared above); TO is the number of offensive assets to choose that are trending up (equal weight), same with TD for defensive (1 for each in this case).
Jack Pizza
Tristan F No saying use a an additional broad filter such as if SPY <> SOME MA TRADE LONG when IN. So if IN first check if overall market is above MA or else don't place any long trades. Then run the typical momentum calculations if it's ok to trade.
Ok let me retest with different lookback periods, from past testing and what we've witnessed I believe we want quicker lookback periods for defensive given if interest rates go up rapidly instead of a typical .25 it happens rapidly a 12 mo lookback is a bit too slow to probably react quickly enough.
Another option is probably manually just removing all bonds from the strategy during rapid rising interest rates like now, I did a rough study of interest rates, when they rise in orderly fashion say .25-.50 there isn't massive hits to bonds, when they rise rapidly like now bonds take big hits. Or maybe we can use Santa24 bond inversion to just use CASH and remove any bond funds for defensive until yields stabilize.
Tristan F
Jack Pizza , I see. The attached has an additional SMA check that can flip an “in” flag to “out". Performance is much worse. This is not too surprising given we are overriding a key value proposition of this strategy: getting back in quickly after a tail event.
See self.ma_eq, self.ma_prd variables that control what you were asking for.
Jack Pizza
Tristan F yeah that didn't work to well not that it added changed much in the other version i had just a tiny bit, this just made it brutal lol
Strongs
hello everybody,
it's been a long time since I posted here in this topic.
A while back I had raised the question of when there would be inflation then TLT would no longer work and even then I started looking for an alternative asset that historically in inflationary periods tends to take on a similar kind of correlation to what TLT has offered us so far and that is the dollar clearly -> UUP. Precisely because of this consideration it is obvious that in periods of inflation the very nature of the dollar as the asset chosen for the exit signal leads to anomalies in periods of inflation, so it was also necessary to formulate a new exit condition that comes into play when UUP exhibits anomalies. By entry/exit signals I refer to Distilled Bear and Vlad's ROC. Having said that I attach the screenshot of the IN&OUT backtest using QQQ as the Asset IN..
Laurent Bonherbe
Nice! Mind posting the code you used?
Peter Guenther
Well done, Strongs, and thanks for sharing your thoughts. That looks promising. I was working with the v8, which I had to manually overrule. I was happy not to lose (much) money between the end of 2021 and the end of 2022. But it seems that your algo actually made money during that period. That is really good.
.ekz.
Brilliant work, Strongs . Thanks for sharing the results.
I'm not actively working on this strategy these days, but I think any additional guidance you can share for others would be great!
TBird
I've been reading Strongs message above carefully and I wanted to add my findings and work in progress to what I think Strongs is doing specifically. Strongs – happy to hear from you if I'm not correct.
I am using Vlad's ROC in/out algo for my modifications.
1.) If TLT is trending down when we try to exit the market position (QQQ), switch to UUP instead of TLT
2.) Also, don't include the UUP rate of change comparison in the Exit check in times of high inflation.
Here are my backtests for the period of 9/1/2021 to 3/30/2023 - so focused mostly on 2022.
1.) Original ROC algo:
2.) The ROC algo with my change of going to UUP instead of TLT when TLT is trending down (doing this for the 2008 to 2023 period lowers the overall return a little, but dramatically reduces max drawdown.)
3.) The additional check of ignoring the UUP rate of change check in the exit condition in periods of high inflation. To be fair, I don't know how that will hold up for the full 2008 to 2023 period yet:
I am hardcoding the ‘high inflation’ check in and am working on a way to algorithmically check for high inflation. If anyone has a good piece of logic for that, please let me know and I will share my code with you.
Strongs
Hi Peter Guenther and TBird , your reasoning is correct, of course the whole thing has to be made dynamic. Otherwise you are overfitting, if you use UUP only when you need it then putting it specifically for 2022. Integration is dynamic and therefore without bias, in the sense that UUP could also be taken in periods prior to 2021/2022, moreover even in the inflationary period 2022 even TLT at certain junctures rendered a negative correlation, using another ROC comparison could to have an additional signal could be one of many viable ways. Also there is to take into account that after 2020 the market has much more abrupt changes, so actually the speed of entry and exit must also be corrected to some extent. I chose not to share the code simply because it is a personal implementation that I have been working on since mid-2021, when with a post of mine here I had raised the concern about the preconception of zero rates and that therefore TLT would not be the asset safe forever. I am also open to further collaboration on similar ideas to IN&OUT in ETF rotation --> check out the post on KEI in collaboration with Simon. For those who want to find me on telegram @Mr_Market94.
TBird
Strongs thank you for your valuable feedback. You’ve done great work finding ways to have positive returns post 2020 and especially in 2022.
Kristofferson V Tandoc
Hi Peter et al.
Based on the previous suggestions above, here is my entry for dual momentum (ROC) bonds (TLT) vs cash (UUP) with QQQ as ‘in’. The ‘out’ selection switches from TLT to UUP when ROC (TLT) < 0 and ROC (UUP) > 0.
Result: I managed to soften the blow over the 2022 period.
I hope people are still working on this as I see a lot of potential in this strategy!
Below are the changes implemented:
Tentor Testivis
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!