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
Jack Pizza
Vladimir and all here my concern about this algo is what is the hypothesis behind it? How do we know the current correlations for the exit signal will continue into the future?
((r[self.SLV] < r[self.GLD]) and (r[self.XLI] < r[self.XLU]) and (r[self.DBB] < r[self.UUP]))
two of the conditions are basically gold / cash related, and the last is metals again / and utilities how solid are these correlations? what happens if they break down in a black swan even? Your strategy will never get an exit signal.
And as mentioned last time the exit can't just be bonds, needs to have an ultimate out of cash or maybe some sort of other momentum calculated assets such as Gold ect.
Guy Fleury
@Vladimir, yes. You changed the stock universe, technically, you are out-of-sample. Especially in this case. The selection process went from one to 150 stocks. For sure, 149 of those had not been seen by your trading strategy. So, it qualifies as out-of-sample. When the selection was for only one stock you had QQQ which in itself represents 100 stocks. And therefore, we should not be surprised if actually dealing with 100+ stocks also worked.
Since the core of these versions remained about the same with slight variations on the same theme we could classify all of the 5 or 6 versions of In & Out in other threads as variants.
I've worked on all of those variants. They all had different stock selection processes, trading rules, trading methods, and constraints. They all gave different answers, some pushing here or there. They all were fully invested and periodically rebalanced. Note also that the trade mechanics have not changed that much since October. We could go further back if we included the stuff done on Quantopian.
In the end, the question will be: which variation of which version will you prefer since they all could be pushed to “extraordinary” performance levels? I prefer the ones dealing with 100+ stocks. It spreads out market risk and reduces bet size.
What is left to do is include other protection measures in the form of having code that would activate should the trend-following signal breaks down, or the market really tanks. We can backtest our trading strategies, but the real objective is to have them survive going forward and we should plan for those “events”.
I see the trade mechanics in need of some improvements as well as the stock selection process and the overall timing of trades. But those are additions that each user should address on their own terms following their own objectives and portfolio constraints.
Frank Schikarski
Hi there, thanks to Vladimirencouragement to try stop loss to increase returns, here is the Trailing Stop Loss and the Portfolio logic plugged into v.1.3. Please don't use my old version from above. My updates are as follows:
Please note, that the level of Stop Loss now depends on the regime defined by the number of pairs in the upward direction. If 2/3 or 3/3 pairs are bullish, the SL is 20%, and if 0/3 pairs are bullish, the SL for bonds is at 15% which means a very rare trigger. Most importantly: if only 1/3 pairs are bullish, the SL is at 11%, defined from the highest high to the current price which significantly improved the results. These numbers are a result from in-sample optimization, but I believe that similar reduction in drawdown will be achievable in the future. In particular, lowering the SL when only one pair is bullish reduces the dependency on all three selected pairs being triggered simultaneously.
In the event that an SL is hit for a single security, a complete rebalancing is triggered 2 days after the exit to fill the empty slot again. These 2 days are also in-sample optimised, but seem to be repeatable, and rebalancing the next day after triggering an SL is not really necessary. Only should an exit be triggered at the same time for a large number of shares, and should these then all rise above the exit price the next day, it would be disadvantageous to wait 2 days with the rebalancing.
I also conducted an in-sample backtest of rebalancing frequency with SL activated. Rebalancing after 84 days (when there was no SL-triggered rebalancing before) was the most promising and did not seem to be a "local optimum". This could be challenged by conducting several in-sample backtests with different time windows.
The most sensitive parameters seem to be the fundamental weights, which I have changed to 85% EV to EBITDA ratio, 10% price to EBITDA ratio and 5% PE ratio. The reason is that these parameters have picked the historically successful stocks quite well in the in-sample back tests, and we don't know if these weights will continue to be very good in the future. We could optimise these parameters with a much higher number of stock picks and see if the parameters hold, and also test them with different time windows. And: we don't have to put an algo live and close our eyes for 10 years, we can repeat the optimisation at any time.
The portfolio logic does not play out its strength with this small number of stocks picks, but can be useful with a larger number of stocks, or if we want to mix stock picks with index ETFs from US or other countries or asset classes with high growth and low correlation.
Results from 2008/1/1 to 2021/1/13 are:
Just to compare risk of v13.b and the original v1.3: with a leverage of 1.43, we can achieve the same historical return, but the historical drawdown decreased a bit from ~38% to ~31%.
Have fun!
Jack Pizza
Maybe another criteria if you're looking at selecting stock is adding a repurchase share filter for obvious reasons, not sure if Quantconnect fundamental data supports that sort of info.
Vladimir
Frank Schikarski,
I like your latest version 1.3b.
Despite it has lower CAGR it has lower volatility, max draw-down, and higher Sharpe Ratio and PSR.
Also it runs reasonably fast.
Thank you for bringing a different flavor to this algorithm.
At the next stage, try to invest the money available from the stop loss exit in bonds.
Frank Schikarski
Elsid Aliaj nice idea! I found these on repurchase of stocks in the fundementals. Also possible would be to continuously calculate the correlation of all available fundamentals and sentiments to price changes and then adapt the fundamentals filter dynamically - volunteers welcome ;)
CashFlowStatement.RepurchaseOfCapitalStock: Payments for Common Stock plus Payments for Preferred Stock.
BalanceSheet.ComTreShaNum: The treasury stock number of common shares. This represents the number of common shares owned by the company as a result of share repurchase programs or donations.
BalanceSheet.PreTreShaNum: The treasury stock number of preferred shares. This represents the number of preferred shares owned by the company as a result of share repurchase programs or donations.
Frank Schikarski
Vladimir interesting thought to replace stopped out stocks with bonds, especially in the case where only 1/3 pairs is bullish.
What do you think of the rebalancing frequency of 84 days, do you think this is too high? Question is, should we let the top runners running (for even more than 84 days) and only replace the stopped out stocks with either bonds or other stocks? But codde will get more complicated...
Jack Pizza
Also regarding bonds maybe should check performance momentum vs different classes such as cash long medium. In case in say where high interest rates return TLT < SHY go into cash as opposed to long medium term bonds always.
Jack Pizza
Also what was the code to turn off the daily rebalancing i think from prior tests the annoying 1 share trades a day didn't add much meaningful performance. Also the bond thing maybe put a threshold for interest rates like > 3% or > velocity of rate hikes ect.
T Smith
Following on from Menno Dreischor comments and Vladimir initial design. I have reduce the signals to just XLI/XLU in order to backtest from 2001 I then optimized the strategy from 2001-2010. We then use the optimized parameters and test 'out-of-sample'.
Using just SPY and TLT (only starts trading TLT from 2003)
Thunder Chicken
@T Smith ,
The issue with your 'out of sample' is it is not out of sample. The moment you optimize any of the parameters by 'optimizing the strategy', all you have done is taken a out of sample test and turned it into an in sample test. An out of sample would backtest the same exact parameters as the Vladimir original strategy but during the period you tested. This is Menno Dreischor whole point. In essence, your test has been fitted for the time period you tested. It is now in-sample.
I believe with out optimization you will see massively reduced Sharpe's, PSR's, average wins, and overall compound returns. Try testing with zero optimization but using the original parameters. Let's see what that backtest indicates for this time period.
-TC
T Smith
Thunder Chicken You've missed the point. The two parameters VOLA and BASE_RET we're optimised on data from 2001-2010.
Optimizing our parameters over that data 2001-2010, the best iteration was:
self.VOLA = 128
self.BASE_RET = 90
Here is the winning IN-SAMPLE backtest.
Bear in mind we are using only 1 out of 3 signals due to lack of data. Would love to hear people thoughts on this as well as ideas to investigate further.
Vladimir
T Smith
Thank you for sharing the results of your research reducing signal just to XLI/XLU.
Thunder Chicken
I used T Smith reduced signal research with my original parameters
self.VOLA = 126; self.BASE_RET = 85
and backtested it from 2002 to 2008
Isn't that "out of sample"?
Thunder Chicken
Hello, Vladimir and Menno Dreischor
Sorry, was at work and couldn't get back sooner. Yes, Vladimir, this is a much better representation of an out-of-sample test. While not representative of the original strategy with all in-out signals, it is something representative of out-of-sample. I think therefore you see a lower Sharpe (.713) and a lower PSR (19.304%).
We could consider looking @ recreating the other in-out signals during the same period to see if it affects performance, with no optimization.
This is a great thread, regardless. I believe folks are learning a lot.
Cheers to everyone,
- TC.
Vladimir
Hi everyone,
It's been over five weeks since I posted in QC
"Intersection of ROC comparison using OUT_DAY approach".
Since then, I have published 6 versions, and more than a dozen versions have been published by Elsid Aliaj, Mikko M, Leandro Maia, Nate Miller, Frank Shikarsky, Guy Fleury, T. Smith.
Each of them has its own flavor and improvements.
I have a few sketches for the following versions, which are variations of v1.3,
but with a different universe selection based on my Quantopian pipeline experience:
v1.7
v1.8
v1.9
There is a shortfall in my time budget, so I'm leaving their final development for later.
I want to thank Jared Broad and his team for giving us the opportunity to significantly improve this algorithm.
Thank you all for your successful cooperation!!!
My regards to a PhD who was here, not to share algos.
Diwang
Hi Vladimir,
Thanks for sharing this great idea. I am a newbie just getting in. I wonder if there is a particular reason why using spy, instead of qqq data when computing vola?
Jack Whisky
Jack Pizza
Vladimir can you share any of these newer versions? 1.7 1.9 or is it just different universe selections?
Vidal boreal
hello, Vladimir
I found that self.count would reset to zero once the server crashes. If TLT/IEF are being hold, it would be sold immediately after the algo restarts.
Is there any way to change the exit conditions of defensive ETF? but not counting the holding days.
Jack Pizza
Vladimir I've been running one of the versions forward live testing, and it's basically been in QQQ / FNGS since the beginning of the year and hasn't been out ever lol. Any insights?
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!