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
Jack Pizza
Zimman
this attached backtest has a lot of momentum stuff, just have to port it over
Jack Pizza
you use a simple price above below like this:
if self.Securities[self.spy].Close > self.sma.Current.Value:
Zimman
thank you, Jack
Santa24
Some recent learnings i had analyzing and extending the IntOut:
Narendra Kulkarni
i think that change from QQQ to SPY makes sense. Its true that QQQ has done really well in the recent past, but then again its fairly concentrated. SPY is much more diversified since it contains banks and energy companies. So even if the switching from QQQ to SPY makes the best test worse I wouldnt trade QQQ and instead trade SPY, since I view the backtest with some level of uncertainty about the future.
Secondly about the bonds, I think its not a good idea to come up with some ideas to change the strategy in response to the recent losses. Its not clear to me that high inflation will always lead to loss in bonds. It depends on market expectations and whats priced. making changes in response to losses often backfires. My suggestion is to keep the code as it is and accept the loss and hope for better times ahead.
Jack Pizza
Narendra Kulkarni the code was based on faulty assumptions of bonds and equities always having a negative correlation…. why would you want to trade something based on obvious fallacies…..
Santa tried to fix it with bonds inverting, and easier way like the few algorithms above is you add cash and check momentum against bonds, if cash is performing > bonds move to cash.
Santa24
I agree with Jack Pizza . Jack Pizza , can you post your favorite example that adds the bond momentum vs cash logic?
Guy Fleury
@Narendra, the choice between trading QQQ or SPY should always favor QQQ. This is a decision that could have been made even 10 years ago. In fact, it could have been made from inception.
SPY holds the 500 most valued stocks, and QQQ holds the highest 100 from the same group, technically ordered by value. The 400 stocks of SPY which are not in QQQ by definition have to be valued less than the lowest-valued stock in QQQ. Those 400 stocks will therefore be a drag on SPY's average long-term performance.
A simple chart can show this.
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
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!