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
Toma
@PeterGuenther It took me much longer to find the time to collect all the information I could about the timeline of changes I made in my strategies. The first time I used DBB and UUP as “canary assets” was in Mar. 02, 2021 in the article at the following link: https://seekingalpha.com/article/4410670-momentum-strategies-djia-stocks I initiated entering a reference as follows: “ The usage of a pair (DBB, UUP) as an indicator for market risk-off periods was introduced by Peter Guenther in a blog on Quantopian.com. A continuation of that blog is now available at the following link: https://www.quantconnect.com/forum/discussion/9597/the-in-amp-out-strategy-continued-from-quantopian/” Because of the delay in editing past posts by Seeking Alpha editors, the references will post only at the beginning of next week.
Meanwhile, I intend to start a new discussion thread here at QuantConnect to complement your thread with information about Momentum strategies published by many authors. Here is the list of authors I plan to mention in that blog: Yegadeesh and Titman (2002), Mebane Faber (2010), Gary Antonacci (2013), Frank Grossmann (2013), Asness, Moskowitz and Pedersen (2015), Keller and Keuning (2016), Yulia Malitskaia (2019), Michael Gettings (2019) and Scott Juds (2020).
Additionally, I will mention two of my articles published by Seeking Alpha. The first is an article in 2014 where I used a three-month look back period for momentum evaluation when most authors were still using a period of 12 months as proposed by Jegadeesh and Titman, period confirmed by Antonacci as optimal for a period of almost 100 years. In my second article (2019), I showed that for a broad class of assets, the optimal momentum period has changed. From 1988 to 2008 the optimal period was 12 months, but for 2008 to 2019, he optimal was 3 years. This is an example as argument for using the most recent past for optimization of strategy parameters as opposed to using very long past periods.
I hope that this new thread would reach many individuals who can contribute to further development of your strategies. Here I want to mention that the reason why I have never posted anything on Quantopian was the fact they were insisting on market neutral strategies that required shorting some assets. On your thread I had the impression that there was much effort to adapt the strategy for automatic intraday trading. All my strategies are long term investments with minimal trading. My strategies have been risk-on since May 2020. When DBB-UUP indicated risk-off I did not apply it because it was overridden by other conditions I use.
Finally, I would like to post a copy of my initial QuantConnect post as a blog on Seeking Alpha. There, some Seeking Alpha members will be exposed to information about your work.
Manoj Agarwala
Stephen David Bennett Wondering if you saw my post above with Link to alternative data that I have assembled for longer duration back testing. Data is from 1995. The data consists of futures and mutual funds that seem to be equivalent to the ETFs being used. https://www.dropbox.com/s/jhbv45w111szult/BackTestingData.csv?dl=0
Carsten
Hi
I tested the effect of the window lenght used for percentage change of the switching pairs. (pairs used to decide on In-OUT)
First test shows the difference between a window length of 2-800 days for the whole period from 2008 until today (one return for the whole period and variation of the window lenght)
Second test, I calculated the return with a rolling window of one year and than looked for the best performing window and its return.
Both test were done for different single pairs. IN-OUT was done with just the SPY. In the first test I switched between SPY and IEF and in the second test between SPY and Cash.
From the first test it looked that around 60 days give the best result/return for the whole period.
The second test, with a rolling window return and picking the optimal window, showed that the optimal window lenght ist ALL OVER THE PLACE….
And now? How should we decide which window length to use and to avoid fitting the window to the best historical result?
Please don't understand me wrong, I'm personally using this method for my investment and I really want to improve the method, but don't know how.
Here the result for the pair DBB/UUP. Upper graphic shows the optimal window lenght.
Following the notebook with the code:
Stephen David Bennett
Hi, Manoj Agarwala , apologies for not replying sooner. Yes I got that file, thanks so much for putting them together. I dissected all of the relevant instruments and created an external data source. I'm still having a bit of an issue getting it to run. I invested about 9 to 10 hours into it last week, hopefully I'll get some more time next week to see if I can fix the issue.
My issue is that I'm predominantly a C# developer. I've done that for 20 years. Python's probably a third language to me, so its slow going. Eventually, I did though at least get to be able to set breakpoints in local copy of lean in visual studio. Progress! Slow progress!
Ws2402
Carsten My guess would be (or maybe not) the window length is correlated to the overall volatility? hence the window length should be somehow adaptive to the market volatility?
Peter Guenther
Toma, thanks for sharing the edits and links. Looking forward to the ideas and articles you outlined above. The change over time concerning what is the optimal lookback period length is very interesting. Relatedly, the question you raise regarding whether to use only recent lookback periods vs very long periods is interesting and is likely to generate a robust debate. We had a bit of that debate in this thread too (e.g. one suggestion was that a strategy should ideally hold for extremely long periods, e.g. 100 years, to be considered valid etc.).
Peter Guenther
Manoj Agarwala, thanks for sharing the dataset that you have created, very nice work!
Regarding your points:
I never expected there to be an issue concerning dividends or splits. My understanding is that the price data is backward adjusted so that, for instance, stock splits are neutralized and do not affect the price signals that are used in the algo. So, my assumption is that, due to the adjustment, there is no effect/bias. Not sure whether you have observed something that made you believe that stock splits and dividends could have an effect (?).
The 5 years lookback, and data not being available before 2008, is a fair point. So, the algo backtest should actually be starting from 2013. I mean, the percentile approach still does what it’s supposed to do in the years before, i.e. it would be looking for the 5% extreme observations; however, of course, the sample of return observations would be smaller in the years before 2013 than in the following years.
Regarding sensitivities, that’s correct: If you change the 5-year lookback period to 1 year and the extreme percentile from 5 to 1, the performance changes substantially. It should get you closer to the v7 performance and probably quite a bit worse, since I removed a few of the signals compared to the v7.
Regarding multi-year down markets: You also raise a fair point here incl. how the algo could be made more robust for these scenarios. Theoretically, the algo would also generate out signals in down markets, since extreme price drops occur also when the prices are continuously declining (the decline is never fully smooth). However, what is true is that there would be times when the algo would go in. I cannot tell how lucky the algo would be in terms of capturing some of the upsides in a constantly declining market; there would definitely be opportunities to capture upsides even in declining markets since these are never only in decline, i.e. there is always a bit of back and forth.
Peter Guenther
Carsten, nice work, thanks for sharing! Here is my thinking: I fully understand the beauty of rolling optimizations runs to derive and test ‘would-be-optimal’ parameter values. However, in (semi)-efficient financial markets where these is ‘no free lunch’, I doubt that we would ever find one optimal parameter value, or a very tight range of optimal values for that purpose. If this one optimal value (or range) existed, then there would be free lunch, i.e. I would use this parameter setting and make optimal returns every single year (!). In my view, this is unlikely to ever exist in financial markets. Therefore, the optimal parameter values are all over the place, since they have to be in somewhat efficient financial markets. So, I think that the only thing we can really hope for is a parameter value that is actually quite sub-optimal when evaluated for each individual year, but is something of a valid average that still leaves us with a bit of excess return. I do not have the final answer, but the three-month lookback period might just be this sub-optimal average value that leaves us with an excess return (?).
Matthew Wang
Jupyter Notebook to Assist with Manual Trading:
I created a Jupyter Notebook that generates up-to-date signals in seconds instead of using signals produced from QuantConnect backtesting, which takes a bit of time. This will greatly assist you if you plan on live trading this strategy manually. It is located in my GitHub repo under In n Out Custom.ipynb
New Out-Signal Idea: Min-Variance Portfolio of Bonds
We currently push all of our money into 20 Year Treasury Bond (TLT) when we are given an “out” signal. Instead of going all in on TLT, I want to buy a mixture of out-of-market ETF's like (TLT), 7-10 year (IEF), and Daily S&P Short (SPDN). To find the composition of these 3 “out-of-market” ETF's, find the Minimum-Variance portfolio fo the 3.
I was able to reduce max drawdown by using min-variance portfolio on out-of-market ETF's
Manoj Agarwala
Peter Guenther I made minor changes to v8 and was able to improve the performance. Basically, I introduced frequent rebalancing. Here is the original v8 performance
and here is the new v8 performance:
Laurent Bonherbe
Hello Matthew! Thanks for sharing the Jupyter notebook, this is really useful for manual live trading.
Do you know why the recent in and out signals are different from the “official” v8 implementation that Peter posted back in October, and also your own version posted here? For example going back in on 2021-10-22 vs 2021-10-29 for your version posted here backtested in QuantConnect, and 2021-11-05 for the “official” v8 implementation…? I am not sure how much of a difference it makes at the end but thought it was worth asking the question and knowing the way you would use this notebook in your daily tradind.
Matthew Wang
Laurent Bonherbe The recent signals appear to be the same. I attached the screenshots of what I'm seeing. Could you point out what difference you're seeing on your end?
I'd just run “Restart & Run All" on Jupyter notebook at the end of the trading day to get the latest signal and trade accordingly. If signal is in, be in QQQ. If signal is out, be in Bonds and maybe short Q's.
Laurent Bonherbe
Matthew Wang I ran your in-out custome 2 here on QuantConnect, and those are the trade dates since 1st of Jan 2020 (putting the precise dates rather than the graph to be razor sharpe precise):
On the collab notebook we have:
OUT on 2020-02-25
IN on 2020-06-12
OUT on 2021-08-12
IN on 2021-10-22
OUT on 2021-11-24
IN on 2021-12-16
As you can see from the above it is directionally OK but we have differences between the 2, sometimes up to a week (2021-10-22 vs 2021-10-29 for the OUT… Maybe I am worrying about something I shouldn't worry about, but I would very much like to explain where those differences are coming from.
Manoj Agarwala
I tweaked some of the parameters (suc as smoothing period) and in/out comparison logic and was able to significantly improve. the recent years performance compared to te original v8. See year by year comparison below:
Wondering if we can combine the two and dynamically pick the best performing one?
Newoptionz
Just what we all love, code with zero comments.
Ryan Smith
Hi @Matthew Wang (how do I tag you with a space in name?), loving the jupyter approach you've taken.
Have you tried a backtest using the Out variance with max sharpe ratio? What are the results looking like on that in comparison?
Does anyone have much experience with pandas to do a vector backtest right in the notebook?
Jack Pizza
And this is how these strategies blow up when both stocks and bonds collapse, i suggested a long long time ago adding an ultimate out of cash. Find my old replies for some detailed thoughts.
Chak
You just need safety measures built into the portfolio management and trade execution portions of the lean framework.
Peter Guenther
That is true, Elsid Aliaj, I remember that you warned about the risk of equities and bonds moving in sync. i.e. both going down. Thanks again for this early warning. Holding cash is really a good idea these days.
If I recall correctly, Goldie Yalamanchi had posted a version of the algo where gold was mixed into the out holdings. In addition to your cash suggestion, this setup may also have worked well in the current context.
Goldie also warned about tech coming under pressure. The warning came quite a bit earlier than the actual decline, but was probably instrumental for some to remain vigilant. I think that Goldie's approach was to mix a tech-focused strategy (eg holding QQQ) and a value-based strategy (stock selection based on Quality Companies in an Uptrend).
Todd
I pulled this from one of my archived presentations circa 2017. My thoughts on robust risk management that is would not be fitted to specific market conditions would be as follows:
If Risk-Off > Then run a 20 and 60-day correlation of MKT security compared to securities in a basket of possbile risk-off ETF securities (Long Bond, Short Bond, Gold, Energy, Yen, Swiss Franc, Commodities, etc), inversely rank the least correlated, check for positive trend over the same period and invest in the top N > If Risk-Off check correlation every N Days and rebalance. One could add some momentum logic as well.
Market regime changes can be very protracted and correlations are not static. Buyer beware. Using ETFs such as DBC, DBA or Currency ETFs can pose liquidity and volume issues if trading in size and market orders.
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!