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
Nathan Swenson
Elsid, I was running live and rather than throwing an error, it simply disabled. When I logged in I simply had nothing running live. I'll have to check if there's a way to check for errors.
Peter Guenther
Elsid Aliaj and Nathan Swenson, thanks for raising the issue! From Elsid's error message it seems that the history call did not result in the usual table with a 'close' column (containing the closing prices). Yet, not entirely sure what happened. Derek Melchin probably would know directly. He has re-written the code using a consolidator logic and this might be a way to avoid the error (?).
Peter Guenther
Not sure whether this can solve the issue but the consolidator version is in the thread Amazing returns = superior stock selection strategy + superior in & out strategy and search for Derek's message "To assist with development of this algorithm, I've added a manual warm up and consolidator for the lookback window. This improves the execution efficiency as we avoid daily calls to the History method." Yet it's probably best to wait for Derek's comment since there may be specifics concerning live trading.
Peter Guenther
Elsid Aliaj: Just attaching here the latest version of the In & Out that I got. Much indebted to Derek and other contributors. It includes the consolidator approach for greater efficiency and code that ensures that sells are submitted/filled before buys. Can't promise that this will address the live trading issue but the features may be useful nonetheless for further testing and live trading.
Jack Pizza
Peter Guenther thanks i'll give it a go let you know if any issues arise
Nathan Swenson
Strategy when back into equities today (12/18). Prior trade was 10/6.
Peter Guenther
First crack on disambiguating the DEBT signal
Following up on DEBT (SHY) possibly being an ambiguous signal; see above the notion of an expected economic rebound causing investors to anticipate the Fed to increase rates at some stage, raising cost of capital expectations. We then said “if we could disentangle investors' improving economic outlook, we might have a counter-signal that could be used to mute the SHY signal in certain situations in which it should actually be interpreted as something that is the symptom of a positive development”.
Attached is an implementation that uses increasing input prices (METL and NRES, above median) to mute the DEBT signal.
Peter Guenther
Chak: Good set of questions and insights there, keep on hacking ;)
Nathan Swenson: Thanks for the live trading update! Fingers crossed that the market does not go down, now that the algo has decided to go back in. Then it would have gotten the rhythm of this cycle wrong.
Nathan Swenson
Nice work Peter! This new version especially excels with 3X funds. I see 71% YoY return using TMF and TQQQ.
Vovik
In_out_flex_v5_try
an implementation that uses increasing input prices (METL and NRES, above median) to mute the DEBT signal.
Excellent example of a curve fitting.
Austin
I found this thread a few days back and have spent several hours since then poring over the archived Quantopian thread and all 250+ replies in this thread. As someone new to quant finance coming from a software engineering background, the discussion alone has taught me so much. Thanks Peter Guenther for having this conversation open-sourced :) and I've learned a lot from Menno Dreischor's discussion about out-of-sample testing.
I'll be following this discussion and hope to contribute, though I'd want to start by validating the algorithm vs hacking returns assuming the alpha is valid. Kevin Davey's book has some interesting directions to take out-of-sample testing that might supplement the work Menno has already done. Cheers!
Peter Guenther
Austin: Welcome on board and good effort working your way through the archive and the thread here! Will be great to hear about your insights.
Peter Guenther
Additional musing about signal ambiguity
I reckon for the DEBT signal we were a bit too late in determining its ambiguity. So, I was wondering whether it might be possible to get ahead of the curve by directly musing about additional signal ambiguity. Below is a first brainstorming regarding the signals, their interpretation in the algo, and thoughts concerning possible ambiguity (i.e. that something that is interpreted as a bad thing may sometimes be a symptom of a positive development). The table below suggests three ambiguous signals, see the note "ambiguity, address".
For those looking for a slimmer algo, this might be an opportunity to try and drop these signals.
For others, this might be an opportunity to think about ways to disambiguate the signals.
Table. Signal ambiguity
Peter Guenther
Note: If your main concern is overfitting at this stage (and before), that is fine. Skip this post and focus on posts concerning testing and distilling signals. There will be posts coming up along these lines and we may achieve a certain level of convergence again later.
Second crack at disambiguating signals: the GOLD pair
We noted that gold can be an inflation hedge, such that the gold price increases when inflation expectations increase (see Table. “Signal ambiguity” above). However, inflation expectations tend to rise when the economy is expected to do well, making a rising gold price a symptom of a positive development in this scenario. This makes the GOLD pair signal ambiguous, since the algo interprets a rising gold price as a bad thing (= flight to safe haven = “market jitter”). The attached algo uses an ETF measuring inflation expectations (RINF, see line 45) to re-assess the GOLD pair signal (see lines 121-125). The logic: To rule out that the gold price increase is due to rising inflation expectations, we only react to the GOLD pair signal when changes in inflation expectations are below median.
Since RINF only started in Jan 2012, I had to catch this via a try ... except construction.
However, RINF could be manually constructed by comparing treasuries with inflation-protected treasuries. I have to explore that option a bit more and may give it a go later unless somebody else might be faster (?) ...
Jack Pizza
Looks like it entered QQQ on 12/18 is this correct? Nathan Swenson Peter Guenther
Nathan Swenson
Yes, Elsid, entered QQQ on 12/18.
Goldie Yalamanchi
Yes that is a very very late entry into QQQ after such major move up. I would just like to add that I have seen a lot of variations of the In/Out algo and the one change that really makes the algo react better without any significant increased drawdown (not using leveraged TQQQ, only QQQ or stocks universe) is to change the self.INI_WAIT_DAYS to 2 as pointed out by Guy Fleury
self.INI_WAIT_DAYS = 2
This makes the algo in the March 2020 covid crash re-enter and stay in since about 4/6. And while it does get a little whip-sawed during the crash, the drawdown was only 15.5% I think one of the lowest drawdowns that I have seen in all the variations of the algo published here. Also, it leaves in tact the SHY indicator as is.
Nathan Swenson
Goldie, in that last run example you have SHY commented out.
I agree that the entry for IN was far too late. The algo needs to react more quickly. There's no way I'm holding TQQQ this late in the move. I am holding some regular equity funds and will follow algo with those.
Goldie Yalamanchi
Nathan Swenson thanks for picking that up.
Still, I have corrected that (commented it back in) and it now stays in the market from Aug - Dec in the QQQ's... as long as
self.INI_WAIT_DAYS = 2
Chak
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!