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
Vladimir
Rock247it
Can someone get my name off this??? How do I remove my name???
On the upper right corner of the thread there is Follow Discussion bell, click on it.
I tried and it's working for me.
Peter Guenther
Impressive burst of passion there, always great to see, and, I reckon, a useful reminder of the several streams/camps we have in this thread with, sometimes, very different views of the world. For further reference, a list (~ chronological order):
1. Engineers – type “Rich data modelists”
2. Engineers – type “Coding experts”
3. Engineers – type “Parameter minimalists”
4. Live traders
5. Sensitivity assessors
Looking forward to these varied streams/camps’ further contributions, although I must say that I am a bit worried about our “parameter minimalists” fraction, but we shall see.
Thunder Chicken
Peter Guenther
Stream: Parameter minimalists
Since much of the discussion lately has been focussed in the Rich data modelists stream, here is a contribution to our Parameter minimalists stream. Specifically, this is a great algo that Dan Whitnable posted on 22 Oct 2020 (see the Quantopian archive). Dan noted that it builds on ideas by Tentor Testivis and others (see his original notes). The algo distils a bear signal by comparing three return pairs. Let’s call the algo the “Distilled Bear” in & out algo; bear in a positive sense = strong. The algo is quite efficient in terms of total return per parameters used.
The Distilled Bear in & out algo
Holdings: In = QQQ, Out = TLT/IEF
Backtesting period: Jan 1 2008 to Dec 18 2020
Total return: 1843%
Sharpe ratio: 1.77; Max drawdown: 14.1%; Compounding annual return: 25.7%
Thunder Chicken
Peter Guenther -
What would be interesting is to see the distilled bear combined with the Momentum Strategy with Market Cap and EV/EBITDA' strategy introduced by Jing Wu, 6 Feb 2018.
Damiano Bolzoni
Peter Guenther have you tried to backtest the strategy between 1/1/2012 and 31/12/2019? What I found is that the strategy shines between 2008 - end 2012, and then again in 2020. Otherwise underperforms a simple buy-and-hold of QQQ (or SPY). The main reason for the great returns over the 2008-2020 timeframe seems to be those two periods....
Thunder Chicken
I think it depends what you hold during that period Damiano Bolzoni. If you hold 2x Treasury 7-10 yrs and 20 years, you'd outperform. The interesting aspect of 2x or3x treasury holdings is simply, we don't ever expect the price to goto zero, much like TQQQ, SSO, or SPXL would.
Damiano Bolzoni
Thunder Chicken I'm running the strategy as posted here, so I will hold whatever the strategy tells to hold...the eyepopping results posted here are backed by 2 timeframes, and otherwise the strategy underperforms a simple buy-and-hold (with the same asset)
Peter Guenther
Damiano Bolzoni: Thanks for sharing these results regarding testing subsections of the backtesting period. Great stuff! I reckon you tested the In & Out, latest version? I recall that Radu Spineanu, back then on Quantopian, was running tests from 2012 onwards and also mentioned subdued performance. Not sure whether you have these readily available, but if so, would you be happy to share some numbers so that people can get a feel for the performance differences (e.g. the period you mentioned, 1/1/2012 and 31/12/2019, and then: In & Out (e.g. holding QQQ) +XXX%, SPY +XXX%, QQQ +XXX%)? That would be very cool.
Irrespectively, I see it the following way: For me, the In & Out is an insurance package that I take out to protect my nicely curated equity stock portfolio from steep drawdowns and then hopefully even benefit from a sell high-buy low type of scenario. Yet, such drawdowns are rare. During calm times, I pay an ‘insurance premium’ that, like any insurance, doesn’t really pay off but instead costs money when nothing super-bad is happening. The insurance premium are losses and/or missed gains due to nervous moves in an out of the market as soon as signs of market stress occur. The algo has multiple radars running (signals) to assess market stress and, hopefully, capture it early via the multiple radars.
The problem is, and this could be an interesting path to explore, that we do not know when to switch our radars on versus off and just be invested in equity without the insurance package and associated costs.
It’s also important to note that, at least in my personal view, the In & Out is not necessarily intended to make money in and of itself as a standalone strategy. This is where a great stock selection strategy is required which hopefully generates returns above the market in times without steep drawdowns. The In & Out is a (possibly costly) guard of our amazing stock selection’s returns. Your data will be useful to assess how costly this guard is. Maybe others are cheaper, for example The Distilled Bear? This will be very interesting to explore further.
Thunder Chicken
Damiano Bolzoni - You'd be correct. It is near impossible to beat a bull market. Most hedge funds and mutual funds do not beat a straight bull market, by any appreciable amount. I have attach the backtest for the period you indicated.
Strategy Net Profit: 314.710%
Strategy Probabilistic Sharpe Ratio: 1.728
Strategy Beta: .328
Please note the Sharpe Ratio and Beta.
-TC
Thunder Chicken
Nathan Swenson - Are you just generating the signal daily, around 11:30, on QC, in order to determine if you have a signal or not?
Nathan Swenson
Thunder Chicken,
Yes, I have my live algo setup to paper trade. I just check it daily for trades and trade my accounts manually. Currently in equities. I still have flex v4 running. I'm still not sure of the best version to run. The new bear distill looks interesting.
Vovik
Peter Guenther,
Can you share a secret how you pick up symbols for signals in your In_out_flex_v5_disambiguate_v2?
The last one was "RINF".
Have you ever looked at it's intraday chart?
For the last week there were only 3 trades 500, 200, 200 shares.
Last year average daily volume of 100 shares per day.
Here is its monthly chart.
Do you think this is a reliable source for TQQQ trading?
Peter Guenther
Stream: Rich data modelists
Thanks for your question, Vovik!
I had hoped that it’s no “secret” why indicators are in the algo since these are individually introduced (use Ctrl + F “RINF”) plus there is an explanation in the code. What sometimes happens is that people cut away the in-code explanations to “save words” in the code; not a good idea, look at a code in a few months’ or years’ time from now and you know what I mean.
The RINF is there to gauge inflation expectations.
Now, how is the indicator specifically used in the code? Check out self.INFL in the code. We want to know, on a particular day, whether inflation expectations are above or below their median. Below is the ~three-month chart for RINF. Does this chart help me to know, on a particular day, whether expectations are above or below their median? I would say yes. I do not need a minute-sharp high-frequency trade price to make that call. Note that close to the median you will always have noise, frequently updated prices won’t make that go away and could even aggravate the issue. It’s also important to note: we do not trade RINF itself (in that case, we would be more highly concerned about liquidity/volume). What we are after via RINF is a coarse indication: above or below median inflation expectations.
However, I think a real downside of RINF is that it only started in Jan 2012 (see my original post). Therefore, the post notes that: “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 (?) ...”
Vovik, are you maybe that somebody who might be faster and thereby contribute to our Rich data modelists stream?
Vovik
Peter Guenther,,
self.INFL is a member of self.SIGNALS
self.SIGNALS = [self.PRDC, self.METL, self.NRES, self.DEBT, self.USDX, self.INFL]
symbols = self.SIGNALS + [self.MRKT] + self.FORPAIRS
returns_sample = (self.history / self.history_shift - 1)
extreme_b = returns_sample.iloc[-1] < pctl_b
if (extreme_b[self.SIGNALS + self.pairlist]).any(): self.be_in = False
As I understand it, if any of [self.SIGNALS self.pairlist] falls below pctl_b,
self.HLD_OUT will be generated.
Do you think "RINF" hitting lowest low after lowest low is a reliable source for TQQQ trading?
Frank DiGiacomo
I've been readng through this entire thread and I find it very interesting! I'm a little confused on one part though.
mom = (self.history / self.history_shift_mean - 1)
What is this exactly caclulating? I don't understand the -1 in there. Is it some rule in matrices?
Peter Guenther
Vovik you have a very good eye there! In the Initialize part, self.INFL should be in the self.FORPAIRS (line 51) bracket instead of the self.SIGNALS bracket (line 52). The intention actually is not to use self.INFL as a signal by itself but to disambiguate the GOLD pair according to the table in an earlier post (Additional musing about signal ambiguity). Updated version attached.
Regarding TQQQ, I reckon trading 3 x leveraged ETFs is anyway a hell of a wild rodeo ride. I would take that risk only with a very measured investment (maybe <10-15% wealth or less). In my view, no matter which in & out strategy you use, or indicators you have included or have not included, drawdowns can be brutal in 3 x leverage ETFs and the in & out precision won't be sufficiently accurate to completely prevent these. One then hopes for a stellar increase in the TQQQ to more than make up for the drawdown.
Updated version:
Total returns: 2092% (worse)
Sharpe ratio: 1.87 (worse); Max drawdown: 13.6% (better); Compounding annual return: 26.8% (worse)
Peter Guenther
Frank DiGiacomo thanks for joining in and no worries. The code snippet calculates a return. self.history contains day-specific prices. self.history_shift_mean contains past averaged prices (i.e. for a particular stock and day, it would be the stock's average price in the range 55 days ago to 65 days ago). For an example stock, say the day-specific price is 110, the shifted_mean price is 100, then we calculate 110/100 - 1 = 10% return (the -1 is required to calculate the return).
Vovik
Peter Guenther,
Do you think "RINF" hitting lowest low after lowest low is a reliable source for QQQ trading?
Peter Guenther
Vovik , thanks for your follow up. My personal view: Yes, I think RINF is reliable. It measures what I conceptually want it to measure, that is inflation expectations. It does so with sufficient accuracy, giving me a daily gauge on where we are at in terms of (changes in) the market’s inflation expectations. Would I use it in the In & Out to trade equity (QQQ, SPY etc.)? Yes, I reckon this is the whole point regarding further developing the In & Out, isn’t it?
Note that RINF does not continuously create new lows, at least not in terms of how the algo uses it. Below is a picture of RINF’s values in the return sample. Currently, it is actually relatively high which I reckon reflects the market’s expectation of an economic rebound.
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!