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
Log Up I've been brining these issues up since Quantopian days so a few years nobody cares to listen, they just keep overfitting the strategy.
Also the OUT is completely arbitrary based on faulty correlations which break down. Hence a simpler normal dual momentum strategy works better.
Because if Asset < Risk Free Rate move OUT
Out also has to have a bucket of bonds vs risk free rate of cash, no point in going to bonds when their absolute momentum is negative vs cash.
The strategy would therefore be:
If Asset > Risk Free Cash IN (in to whatever highest momentum asset or hold top 5 assets)
Because if Asset < Risk Free Rate move OUT (either bonds in a low rate env or cash in a rapidly rising rate env)
The SLV < GLD and all the sector non sense is based on faulty correlations that would break the strategy at some point in time along with OUT just being bonds another fault correlation.
Log Up
Jack Pizza I am not much experienced trader myself, but I do agree with the pitfalls of hard coded assumptions/correlations you mentioned. We have many periods in history where stocks and bonds both fell together, so felt should it accommodate to invest only if bonds are faring better than other available alternatives.
Carsten
@Jack Pizza
I had similar issues with the overfitted versions.
The question is, what is robust?
I totally agree, a dual momentum is quite robust.
Voltility should be, but there a some periods, where high volatility as well delivers good gains.
Tested as well first month / second month VIX futures. If you plug them into a Hidden Markov Model you don‘t need to specify a length component as the HMM figures it out. worked very well in the 2008 episod, performed poor in 2015/16 and performed excellent in 2020.
Than there is the good old price vs 200DMA, if one uses the volatility or ATR to decide if the price is significantly above or below the performance is not bad.
Some more thoughts On robust indicator?
Jack Pizza
Carsten it's basically a fools game based on luck, the thing that has shown semi promise is momentum if you can stomach 40-50% drawdowns which basically make it as good as all in on the stock market end of the day lol.
But you see they love hiding that fact by showing monthly drawdowns because well everyone is using monthly drawdowns, instead of we purposely want to mislead you, as if you knew the truth you wouldn't give us your money to invest.
On here it just turns into Ego contests, of I have the most popular thread on Quantopian / qc. Dual momentum backtests are highly flawed too especially with bonds as the out. Even Cash as the out doesn't quantify risk, say you're out everything is honky dory and the dollar collapses 40% overnight…
They geniuses laugh and grin ohh that will never happen, like it hasn't 100 times over globally throughout human history. People's don't appreciate risk, and think it will never happen to them, until it does over and over. Then all the experts go and hide not to be found.
“The day after the U.S. dropped its second atomic bomb on Nagasaki, Japan closed down trading on the Japanese Exchange. Although Japan would surrender less than a month later, officially ending World War II, the Japanese Stock Exchange would remain closed for nearly four years, finally reopening on April 1, 1949. Following reorganization, the TSE emerged as the largest of five post-war exchanges in Japan.”
Ohh it can never happen in their brains, what would you do if your'e invested and the stock market is closed for 4 years, if not totally bankrupt along with the companies or index you had invested in? Even excluding war there is so much counter party risk its insane, like dominoes they'll all fall.
What happens with the DTC Cede and Co. which is technically the rightful owner of almost all Assets in the world since it's their name on the stock certificates and titles, says we own everything sue us in court if you want it?
See where I'm going with this? Every single strategy i've personally tested researched read about, none of them achieve anything above 1:1 performance/dd long term. You'll always have inevitable drawdowns even making the ratio 1:2.
My conclusion from all this is you can't escape drawdowns from a strategy.
My further conclusions from a risk standpoint as far as investing goes is.
Operating Farmland, war happens your farm blows up who cares its just land, replant seed after. Weather ruins crops for a year, again replant next year. Water issues, use new technologies like desalination. Everyone will always need food….
Gold as basic insurance, if you have some sort of trading strategy, trade it through actual futures where you use physical gold as collateral on CME, but you at all times are physically owning it. Internet goes down, CME goes bankrupt, war, yada yada who cares, you have no counter party risk as you physically own it somewhere, after the dust settles it's a long time.
Even gold just because it's worked for human history, there could be some time in the future from say asteroid mining where it becomes basically worthless, or some massive discovery.
I would hold other non food type commodities mostly metals physically and like i said maybe run some momentum strategy if you can stomach the massive drawdowns. Assuming momentum is a psychological phenomena and not another overfitted mined hypothesis.
Hope this confused you a lot but hopefully it helps you from losing a crap ton of money…. I wish i knew what a robust indicator was to limit drawdowns and maximize performance, but I have yet to find it unfortunately.
So invest with a barbell type Taleb mindset, 95% in farmland, gold, 5% gamble on crypto, high flying strategies, if they last a year or two and you make 1000% great take it out put it on the barbell, and repeat.
Always remember there is a lot more risk like 100000000% more than majority of people care to even bother thinking about.
hope this somehow helped lol.
Peter Guenther
A comment on the current overfitting discussion
It is an important part of the In & Out discussion’s evolution that we constantly revisit the overfitting issue. The latest resurgence of the issue was mainly driven by an underperformance of the TLT ETF which is used in the latest in & out versions as the out holdings when we are not in, i.e. not invested in equities. Some comments, as a shorthand, simply seem to refer to the previous In & Out versions as the ‘overfitted versions’, with the TLT underperformance just being an additional proof that the In & Out has been overfitted as claimed in earlier comments in this thread. However, this conclusion does not seem to be valid to me.
Overfitting of what?
In the Amazing returns in & out thread, I try to explicitly pinpoint the three key components/characteristics of the in & out algos:
1. The in holdings selection
2. The out holdings selection
3. The market timer property
Recall that earlier overfitting discussions were mainly about the number of parameters that the In & Out uses and that these are too many and clearly show overfitting. Note that these parameters are neither used for the in holdings selection nor the out holdings selection, the latter of which has led to the current underperformance (the TLT decline). Instead, these parameters are used for the market timer. In the Amazing returns in & out thread, I argue that the market timer has worked remarkably well during the recent equity downturn. The market timer is arguably the soul of the In & Out. Therefore, it appears to me that the recent episode is not very suitable to demonstrate overfitting of the algo along the lines of earlier claims in this thread.
Have the out holdings been overfitted? First, it is important to note that this question has little to do with the previous overfitting discussion. It is a new question since it is about a different component. Second, in my view, overfitting is a process in which models are repeatedly estimated and optimized to fit the data better (i.e., to maximize the total return). Going through the discussion in the in & out threads, I see little evidence for such an approach on the out holdings. It seems to me that bonds were listed as the out holdings in my very first post on Quantopian. Since then this component has basically been ignored, almost neglected. There are no parameters dedicated to this component other than a hard-wired ETF that is listed. I do not recall significant efforts to (over-)fit this component. Quite the opposite, the lack of such efforts has sporadically been noted in this and the other thread.
It seems that the issues we are seeing at the moment are a result of underfitting or lack of fitting, instead of overfitting. Specifically, the out holdings selection has been ignored and requires work.
Jack Pizza
Hey Peter Guenther actually the biggest performance issues seems like the timing model, it goes in right before the collapse. You can easily just swap in BIL (cash) instead of TLT, and see it takes a massive hit because it's IN instead of OUT.
Trying some tests with an MA filter and stop losses.
Jack Pizza
nevermind had a wrong version seems like, I tried adding an MA filter doesn't seem to be working though… added to line 137.
Jack Pizza
Also add momentum approach mentioned in the stock selection forum. Would add it to both the IN and OUT portion so have maybe 4 ETF's in IN and 3 in OUT and select highest momentum one
Jack Pizza
I would add it from the other momentum algorithms, but the ordering is a bit weird and i can't debug easily on here, would probably take the symbol and concat / append it to _IN and _OUT after the momentum check is ran. I'll try working on it later, but maybe if someone has time can do it much quicker.
Momentum would be 1,3,6,12 month with weights of 12,4,2,1
Jack Pizza
A simple stop loss protects losses as opposed to cash. straight cash you are at around 16%/16% Returns/Drawdown, with iEF + stop loss 1%, you're at 20%/!8%
Zimman
Manoj Agarwala , i have been trying to add momentum indicators on your version without success…. how would you add moving average ?
Jack Pizza
Zimman
self.spy = self.AddEquity("QQQ", Resolution.Daily).Symbol
self.sma = self.SMA(self.spy, 50, Resolution.Daily)
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.
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!