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
Vladimir
A cleaner version
Jared Broad
Thank you for sharing! Glad to have you on the platform 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.
Chak
Hey Vlad,
My private version is similar, but you shared it first so you get credit. :)
To further help you, dual momentum hits a snag in calculating share quantity when holding more than 1 equity. For example, when holding TQQQ and SPY and switching from SPY to FDN/QQQ, you end up going into margin. There isn't an issue in cash account situation.
Thunder Chicken
Vladimir - Hope all is well. If I wanted to diversify the ETF portfolio how would I do so? I want to trade 2 ETF's as opposed to 1.
Also, Happy New Year!
Jack Pizza
Vladimir are you able to add parameters to what you think is necesarry and I can run an optimization on them?
Jack Pizza
I added this testing now someone lmk if this is correct way to declaring parameters.
VOLA = self.GetParameter("VOLA")
BASE_RET = self.GetParameter("BASE_RET")
RET = self.GetParameter("RET")
EXCL = self.GetParameter("EXCL")
LEV = self.GetParameter("LEV")
Jack Pizza
tried running it fails
[ERROR] FATAL UNHANDLED EXCEPTION:<>c__DisplayClass27_0.b__0(): Python.Runtime.PythonException: TypeError : must be str, not int, at Python.Runtime.PyObject.Invoke (Python.Runtime.PyTuple args, Python.Runtime.PyDict kw) [0x00033] in :0 , at Python.Runtime.PyObject.InvokeMethod (System.String name, Python.Runtime.PyTuple args, Python.Runtime.PyDict kw) [0x00007] in :0 , at Python.Runtime.PyObject.TryInvokeMember (System.Dynamic.InvokeMemberBinder binder, System.Object[] args, System.Object& result) [0x0003e] in :0 , at (wrapper dynamic-method) System.Object.CallSite.Target(System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,object), at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid1[T0] (System.Runtime.CompilerServices.CallSite site, T0 arg0) [0x000fa] in <92922d9bda2f4e1cba9242d052be6d43>:0 , at QuantConnect.AlgorithmFactory.Python.Wrappers.AlgorithmPythonWrapper.Initialize () [0x00045] in <456b6029629b49049524ae2dfa9834ab>:0 , at QuantConnect.Lean.Engine.Setup.BacktestingSetupHandler+<>c__DisplayClass27_0.b__0 () [0x000a5] in <3cbab1cc8eab4b4da38d16990aacef7a>:0 ,Engine.Run(): During the algorithm initialization, the following exception has occurred: TypeError : must be str, not int, at Initialize in main.py:line 109, TypeError : must be str, not int,ApiConnection.TryRequest(backtest/status/update): Error: The operation has timed out.
Vladimir
Elsid Aliaj,
This thread not about optimization of parameters but algorithm itself you wanted to have sometime ago.
Please do not go beyond the topic.
Vladimir
Here is Intersection of ROC comparison using OUT_DAY approach v1.1 (diversified static lists)
Example of parameters:
STOCKS = ['QQQ','MSFT','NFLX']; BONDS = ['TLT','TLH']; VOLA = 126; BASE_RET = 85; LEV = 0.99;
Jack Pizza
Hey Vlad,
Any specific logic of listing specific stocks as opposed to just a Fang ETF? Replaced QQQ and the stock selection with just FNGS and it doubled performance while maintaining the same drawdown.
Only backtested 2020 as I don't know FNGS inception date.
Nate Miller
Hi Vladimir,
Super interesting, thanks for sharing!
Can you share the derivation of this logic from `daily_check`?
wait_days = int(vola * BASE_RET) period = int((1.0 - vola) * BASE_RET) r = self.history.pct_change(period).iloc[-1]
.ekz.
Great stuff Vladimir.
Thanks for being open and sharing this. It's very helpful.
Vladimir
Nate Miller,
Can you share the derivation of this logic from `daily_check`?
The original "In & Out" strategy, published on the Quantopian forum thread
"New Strategy - In & Out" Oct 4, 2020, had only 4 sources SPY, XLI, DBB, SHY.
There were 6 constant parameters: waitdays = 15, period = 58 and thresholds for each source.
Some participants was asked where these magic numbers came from because the results changed
significantly due to a slight change in parameters.
Tentor Testivis, the great "In & Out" contributor, on October 12, 2020, proposed the idea of
making them adaptive to volatility.
The idea:
Using SPY's volatility to replace the magic numbers
vola = hist[SPY].iloc[-126:].pct_change().std() * np.sqrt(252)
waitdays = int(vola * 100 / 3)
per = int((1 - vola) * 50)
Implementing the idea as is dose not give grate results so in my
"Price relative ratios (intersection) with wait days" Oct 16, 2020
I modified Tentor Testivis idea to what I have been using since then.
vola = self.history[[self.MKT]].pct_change().std() * np.sqrt(252)
wait_days = int(vola * BASE_RET)
period = int((1.0 - vola) * BASE_RET)
You are welcome to modify these empirical formulas.
Vladimir
Elsid Aliaj,
Replaced QQQ and the stock selection with just FNGS and it doubled performance while maintaining
the same drawdown.
It's not surprising.
As far as I remember, FNGS = ['TWTR', 'TSLA', 'AAPL', 'FB', 'GOOGL', 'BABA', 'NFLX', 'AMZN', 'BIDU', 'NVDA']
Mikko M
It's also important to note that they are FAANGs for a reason - they are some of the most valuable, fastest growing tech companies available so selecting them definitely contains a look forward bias.
.ekz.
Vladimir: Thanks for this explanation. Very helpful!
Nate Miller : Here's an archive of the original thread from Quantopian, that has all the backstory, and very insightful context on some of the decisions that were made. It is helping me understand as well.
https://quantopian-archive.netlify.app/forum/threads/new-strategy-in-and-out.html
Also, , here's a comment from Vladimir in that thread, relevant to your question on the logic. Be sure to take a look at the other comments immediately following ( and preceding it ).
Hope this helps.
--------------
Vladimir
Oct 17, 2020
This is not a modification of Peter Guenther “In & Out” but another algo using Peter Guenther's
wait days approach.
I am trying to not use seven hard coded variables: (DBB = symbol('DBB'); context.WAIT_DAYS = 15;
context.RET = 57; thresholds(-0.07, -0.07, -.006, .07)),
because I was taught that "each undisclosed coefficient is the coefficient of our ignorance".
The goal is to get similar results using as few variables as possible.
I modified Tentor Testivis recommendation to use volatility adaptive calculation of WAIT_DAYS and RET.
I find that union of four factors used in original algo is less reliable as the output is dependent on
any single factor and there may be many of false exit signals.
Therefore, I used price relative ratios for each two factors (bull and bear) and signal as intersection
of them, where the results depend on all four factors (signal conformation).
The factors and variables are not optimized as a strategy itself so you can get better results.
You can also add another pairs of bull and bear factors.
Nate Miller
Thanks Vladimir and Ikezi Kamanu for the info! Very hepful indeed.
I'm having a lot of fun picking apart this algorithm to learn how it works. Wanted to share my results.
First, I've gone through and attempted to annotate the code. This is exactly the same algorithm that Vladimir posted, just with comments and re-names that might be helpful for a rookie.
Second, I did a parameter sweep (love that tool!) to understand sensativity to a parameter that I call `time_constant` (`BASE_RET` in Vladimir's original code). Overall it does not appear to be devistantingly sensative. This algo still beats the market's returns if that parameter is in the range [50 150]. I don't know a good way to share the results of a parameter sweep, so I've attached an image of the output.
Vladimir
Nate Miller,
Thanks for the quick analysis of the sensitivity of the parameters.
In the future, please do not change the names within the algorithm and the name of algorithm itself.
This can interfere with collaboration.
It is a good practice to put the header of the original algorithm in your cloned version.
Vladimir
Ikezi Kamanu,
Thanks for the support and the link to the Quantopian forum archive.
.ekz.
Thats fantastic, Nate Miller
I was going to do exactly this! Add comments to help new folks (like myself) have context.
From a previous comment I also learned that Vladimir is sensitive about variable names, so that is something to be mindful of (read the first message in this thread). Thats a small price to pay for his contribution to the community, i think. That said, i could never figure out what "RET" stood for. Now I know it is a Time constant, so thanks for that :-)
I do agree that keeping the name of the strategy consistent is helpful for collaboration, and I'm Looking forward to doing just that, when i have more free time.
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!