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
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.
Robert McLellan
Pardon me for poking my nose in this thread but distilling what I understand of the strategy it hinges on a negative coorelation between the market (represented by SPY) and long term treasury yields. Would then not a simple correlation track between the two be enough of a “get to cash” signal to bail out?
I've cobbled together something similar for my algo by leveraging a sample posted in another thread which shows a pretty good signal in the June-July timeframe of this year.
Robert McLellan
Stole the code from here if anyone is interested.
Jack Pizza
Wouldn't dual momentum of say bonds : cash work as a better predictor than correlation? I saw some of the correlation stuff above and it doesn't seem like it can be a good enough predictor as it's bouncing all over the place.
I have a dual momentum strategy with bond mutual funds, that does well and has moved to cash pretty much all these times corona ect.
Seems like it would work as a good out signal here if cash > bond funds stop trading and move to cash.
Robert McLellan
Well I think the obvious answer is probably to do both and take a look. My comments were based on the view that I see this whole strategy hinging on negative coorelation between bonds and stocks. If that starts to break down the strategy may no longer hold weight.
I'm not saying you're version won't work or isn't better but it seems to provide decent signal for me.
Quantum Bunny
New to this thread, I would imagine someone would have raised this question already. Why not using actual oil, gold, metal prices for a much longer backtesting period pre-2008?
Zimman
Is anyone using this for live auto trading?
Jack Pizza
sorry to hijack thread Vladimir how can i get in contact with you? Want to discuss some potential investment ideas.
Log Up
Based on current situation, what if stocks and bonds both fall? currently stocks are down and bonds are also down due to high inflation worries. in that case we will lose money if we invest in bonds right?
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!