This is the original name of the algorithm that I created as a result of a successful collaboration
on the Quantopian forum thread "New Strategy - In & Out" in October 2020.
Unfortunately, the collaboration did not continue on the QuantConnect forum.
At least I am very uncomfortable with the strange names used by Peter Gunther in the algorithms,
such as "Distilled Bear", variable names and decision making logic.
This algorithm unlike those from Peter Gunther has three pairs as a source, two parameters and
concensus of all three for exit signal.
I did not optimized parameters, so you can get better results.
I want to thank Jared Broad and his team for giving me the opportunity to recover one of
my favorite algorithms.
Happy New Year to all
Gv
Vladimir.....Doesn't it makes sense to select something like top 10% performers from QQQ underlying stocks rather than including individual stocks like MSFT, NFLX etc?
Chak
Vlad provided the code sample as a template.
Jack Pizza
Vladimir i actually found the parameters to be quite robust through a range where maybe CAGR went down 2-3% and DD up 2% or so.
But I did run across some weird massive performance difference for some values.
For example changing RET to say 80 increases DD 2x to almost 30% for some weird reason while other multiples usually do not.
This is strictly speaking about VOLA and RET.
Vladimir
Elsid Aliaj,
The original strategy has two constant parameter:
VOLA = 126; BASE_RET = 85; Did you find anything better?Jack Pizza
For the full backtest no, for single years yes for 2020 VOLA 100 and RET 50 worked better, but full backtest lowered CAGR by 2-3 and increased drawdown by 3, so not worth it in my opinion.
Also obvious observation heavy returns are driven by bonds. Would love to see some sort of black swan implementation with options but might be outside the scope of this discussion.
So if even bonds breakdown their negative correlation to stocks you can have protection. The returns would more then cover the cost.
Vladimir
Gv
Vladimir.....Doesn't it makes sense to select something like top 10% performers from QQQ
It definitely makes sense, but we're not ready for it now.
The backtest can run 60-90 minutes.
.ekz.
@elsid: I am working on an options variant, and will share when done. It's my first algo on QC, so it may take some time.
All: I think the strategy may benefit from walk forward analysis. If we find that the strategy can in fact be walked forward, then periodic optimizations to VOLA and RET will become part of the live deployment process. For example, we might find that re-optimizing these every 18 months might be the right frequency. WFA would help us determine this, or if WF is even applicable to the strategy. Just a thought.
Jack Pizza
Ikezi Kamanu yes that would be something to consider. Are you working on the options strategy to use options for all the trades? Or just as black swan insurance? Are you familiar with Talib's work?
.ekz.
Yes, I was considering using options for all the trades, but it should be trivial to add black swan insurance.
I am yet to read Talib's book, although I do have a copy.
Mikko M
Here is a version that dynamically selects top 10 gained (ROC 252) tech companies instead of using a fixed set of stocks.
Jack Pizza
That's cool would be super interested in it, especially the black swan parts.
Basically the whole premise is take whatever strategy and use a tiny fraction for insurance which makes sense. Just like you insure your home.
Enjoy your strategies performance with a 1-2% insurance drag. Only thing is I'm not sure if you can insure your whole portfolio that cheaply in case of total collapse.
Think the numbers worked out too 1-3% per 16% of drawdown.
.ekz.
I've adopted portfolio insurance with VIX calls. 30DTE, 30 Delta. We could add that to the strategy. Here is a link with more detail.
https://seekingalpha.com/article/613051-buying-vix-calls-as-a-portfolio-hedgeWe can chat about this off-thread so we don't digress / tangent off the main conversation. I'd imagine QC has some mechanism for direct conversations.
https://seekingalpha.com/article/613051-buying-vix-calls-as-a-portfolio-hedgeLeandro Maia
Ikezi,
I would also be interested in these hedge strategies, although I would probably not be able contribute much. And I'm sure I wouldn't be the only interested. So perhaps, instead going to direct conversation, we could set a separate thread.
Thunder Chicken
Ikezi Kamanu and Leandro Maia
I don't believe VIX options are available on Quantconnect. I have requested the index a few times. No dice. So, I don't believe options would be available on the platform. I am sure Jared Broadmight be able to point us in the right direction, but I am unsure. They might have a solution with external data but I am unaware of it.Jared Broad
-TC.
Guy Fleury
@Vladimir. nice work. I particularly like that smooth equity line, it shows built-in alpha. Or, if you prefer, you can't have that line without built-in alpha. And that can be taken advantage of.
The following charts used your latest version (1.1).
In the first chart below, leverage is at 1.4x, it uses TQQQ and TMF, and managed a 92.5% CAGR over the 2008-2020 period. It has a beta of 0.091, which in itself is remarkable. It means the strategy fluctuated a lot less than the market in general. It did not trade TQQQ or TMF prior to February 2010. Still, the strategy held on to a 506,659.63% gain, going from 100k to $506,759,628 over the trading period.
You could go for more by pushing for a leverage of 1.5x. Doing so increased the strategy's beta to 0.10 and its CAGR to 107.6%. This more than doubled the ending equity to $1,353,637,166. Again, all based on the original stake of 100k. Note that there were other changes to the strategy as well.
Increasing the initial capital to 1 million would add a zero to the above equity numbers. The strategy is scalable to that level.
It should be observed that we can quit a trading strategy any time we want. It would result in getting what is displayed as equity at the top of the chart at that time.
Based on your chart, where was the risk after the first year? What you could lose was only part of the accumulating paper profits. And with such an equity curve, quitting along the way would more represent a stop-profit scenario and some lost profit opportunities. You would be losing the last few years of compounding. For instance, 100k ∙ (1+0.40)^12 - 100k ∙ (1+0.40)^10 = 2,776,845. Almost as much as you would have gained in the first 10 years (2,892,547). There was no preferred time to quit on such an equity curve. And if you added two years to this scenario, those two years could be worth 5,442,616 and raise the total outcome to 11,112,007. The point being that it is the last few years that might count the most, and to get there you have to survive all the prior years.
If you did the same calculations for the difference between year 14 and 12 but at a CAGR equivalent of 0.80, you would get: 100k ∙ (1+0.80)^14 - 100k ∙ (1+0.80)^12 = 259,130,229. IMHO, that is what is at stake. And one could do even more.
It is our job to try to extract the most we can from a trading strategy. We are allowed to game it after we have shown ourselves that it could be worthwhile and gained confidence in these newfound trading methods.
Thunder Chicken
Guy Fleury - You are going to need to be very careful with TQQQ. I'd recommend a 2x or keeping your exposure to TQQQ low. A few bad days on QQQ, let's say down 5% per day for 5 days, which he saw 9 months ago, could easily wipe out your portfolio. I am also assuming this algorithm works flawlessly, which is highly suspect on a walk forward.
Be cognizant of the potential risk you are taking and consider diversifying across assets. Just a thought.
-TC
Guy Fleury
@Thunder Chicken, I am well aware of the dangers of trading 3x-leveraged ETFs. These are not instruments to be held over the long term. Look at the long-term chart of SQQQ for instance. It has not looked up very much. And you can find a lot of those.
However, this is a trading strategy where you do not hold that long. And it is “very sensitive” to price fluctuations. Technically, all it does is trade QQQ where price variations are multiplied by 3. It is still trading the average of the 100 stocks in QQQ. Top ten holdings account for 55%(AAPL, MSFT, AMZN, TSLA, FB, GOOGL, GOOG, NVDA, PYPL, ADBE). And such names have not been that bad over the past 12 years, nor has QQQ.
Nonetheless, the strategy switches to bonds at the first sign of trouble. As the chart shows, even the bad few days of 9 months ago (or the whole of 2020 for that matter) did not do that much harm since the strategy more than recovered. Regardless, we can override our trading strategy at any time we want and execute a massive manual stop-loss. Doing so, at any time during the simulation period would have resulted in substantial profits (high returns) up to that time.
We can not stop the market from fluctuating, but we can move to the sidelines and that is what this bond switcher does. It has, on average, a very low pain threshold. Just like the other versions of the In & Out strategy. Even though each of those programs have different trading procedures, they all had sensitive bond switching procedures. These can be improved upon but that is another story.
You seemed worried about things the program might not even let happen. It will switch to bonds at the slightest downward pressure and remain in bonds for as long as it takes thereby avoiding those bottomless pits to oblivion. But, still, we should use caution.
This is why we do simulations in the first place. It is to see if the trading methods used would have been successful. Once we have that, we can concentrate on: can these trading procedures hold up going forward?
Here is a little fact. It takes 21 successive 10% loss on QQQ to lose 90% of its value. Due to the 3x leverage, it would take only 7 successive 10% loss on QQQ for TQQQ to lose 90% of its value. It is the reason why, should you want to play TQQQ, you should have a sensitive switcher. But we should also note that going for higher risk can lead to higher returns. And the question becomes: how much risk can you withstand? Or, can you play the game in such a way that the total risk is reduced to your acceptable level? You would see TQQQ really fly should QQQ have 21 successive 10% gains!
Guy Fleury
In a previous post somewhere it is said: “And one could do even more.” I do not like to say things like that without showing that it can be done. Actually, even before saying that, the test had been done. But, I was advised not to push it and settled for what was presented. Still, one could do more.
So, here it is. Leverage went up to 1.6x. Other stuff was changed too, but the most impactful was coming from the compounding of profits generated by the compounding of the bet size. The result: almost doubled the outcome compared to the last chart presented.
I do not dare to again say you could push for more. But...
Vladimir
Guy Fleury,
This strategy has two opponents.
Menno Dreischor
The reality is, that it is likely, it will not just fail to meet expectations, but generate
negative alpha in the long run.
Arthur Asenheimer
But personally I wouldn't risk my money for it for the reasons mentioned above.
Can you support this strategy there with a less risky version of your algorithm.
Guy Fleury
@Vladimir, I read the thread you referenced. I wasn't aware of it. Now, here is my take.
I agree with the findings of de Prado and @Menno's apprehensions about overfitting. This might sound contradictory, but I have read a few hundred of those books and papers to that effect. There are some holes in the whole vision that is projected but I am not to write a thesis on that.
This goes on the side of all trading strategies eventually fail. That is not something I agree on.
Every share of every US stock is in the hands of someone. Some of them have been there for some time (decades) and what we can observe without even a backtest is that stocks have had a long term upward trend. The simple method of just holding to a diversified portfolio would have given a positive outcome where all you had to do was sit on your hands for a generation or two. A good example of a strategy that did not fail is Berkshire Hathaway that has been there and prospered over whatever the economic cycle for over 50 years under the mantra: do not bet against America. I make the same bet. And therefore, over the long term, I do expect the markets, in general, to go up, not down.
I find that premise important as it should guide whatever trading system I might design. If your premise is that eventually, you will have, on average, higher prices your betting system should favor long positions. And if you think the market will fail you, then short the thing.
Some say that you need predictive powers to outperform. I would dare to advance that it is not necessary or even required. All that is required is to participate in the game, that is: be long when prices are rising and do not be there when not. Therefore, switching to bonds or equivalents on market downturns appears as a reasonable proposition.
What you really need is “something” that will declare the trend as up or down. And whatever it is, you should have your trading strategy follow it. Meaning you take longs when “you” declare the market or the group of stocks you intend to trade as going up.
The what you use to declare the trend would appear consequential. That is why we do backtests to find out if our vision of things would at least have prevailed over past market data.
It is not enough to design a trading strategy, you also have to go a step further by gaming it.
Because here is where I see a problem. Whatever simulation you do, you are dealing with a one-time occurrence. Any of the stocks you might touch in your strategy have only one history. They are all one of a kind. And there is no statistical significance, except that you are always at the right edge of the chart. An example: Lehman Brothers took 140 years to reach its historical high and only 9 months to go bankrupt. Whatever statistics you had on Lehman up to the year before its demise was completely useless and even worse, detrimental to any portfolio. Because of scenarios like this, and there are a lot of them, we as developers, should exercise extreme caution. The data we are feed needs to be validated or you should play 100 stocks or more at a time in order to reduce the size of your betting functions.
Short-term trading is simply gambling. It is investing but of a particular kind. You win or lose based on what you selected for the duration of your holding period that you be long or short. And that puts you right back to your bet on America: a positively biased probabilistic trading environment.
My point is: can you game a system better? How far and by how much? Is trading QQQ a real market risk since it is a market proxy? Trading on QQQ is equivalent to trading the 100 stocks it is composed of. Can you slice QQQ into sub-intervals where you take long positions only when you declare its trend as up? And this, that it be related to the market or not.
The most basic of questions: what will you use to declare bets on and bets off?
Of the different versions of In & Out, I prefer this one. It is more stable and more risk-averse than the others. I do not mind the drawdowns so much since I put them as inevitable whatever I do. On the other hand, I seek volatility while in a position in order to extract a larger profit.
Version 1.1 had an average win of 6.92% and an average loss of -0.78%. This should be viewed as: the average stop-loss was -0.78% while the average stop-profit was 6.92%. It shows how sensitive to market downturns the strategy was. It did not tolerate a 1% decline in value on the average position.
You combine this with a win rate of 78% and I have to declare that there is alpha built-in!
So, as said before, nice work. Your strategy did not need to be predictive. At its core, it is a simple and sensitive trend-following system which coincidentally could be viewed as if predictive. It expects the next day to be in the same direction it just declared.
What I did is amply the gaming side of the equation. If you take the case with the 1.4x leverage, the average stop-loss was -1.69% and the average stop-profit was 15.18% with a win rate of 77%. I am not surprised that it generated a 506,659% total return on its 100k stake. You could do even better by pushing more on the governing equations. And that was also illustrated. The last chart presented had a 2,000,000+% total return. This is enough to invite back the notion of overfitting.
We have nothing where we can say: this strategy is “fitted”, this is the perfect fit. But, some can declare: it is overfitted. Compared to what? Where is the rationale? That the future will be different from the past. But I already know that as almost self-evident. A trading strategy will behave differently going forward? Absolutely. My modifications to your strategy showed that you could push version 1.1 to go from 8,518% to over 2,000,000%+ total return and anything in between. At what point do you declare it “overfitted”. If it was overfitted at 100,000%, what was it at 500,000%? Do we have a measure of overfittedness? The range provided here is mind-blowing. You can change your look on this strategy, change its objectives, increase and decrease parameters and you can get such a wide range of outcomes. All stuff we have to think about.
Vladimir
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!