Intro
Superior algo returns can be thought of as being the result of two components: a great strategy regarding ‘what stocks to buy’ (the stock selection component, SEL) and a ‘clever timing’ (the in & out component, I/O) regarding when we are ‘in’ the market and hold the stocks versus when we are ‘out’ of the market and hold alternative assets such as bonds. We often focus on optimizing SEL and tend to neglect I/O; thus, for an important discussion of recent I/O tactics, see here.
Focus of this thread: Optimal SEL + I/O combinations
It is worthwhile to separately optimize SEL and I/O. However, the ultimate total return will also be determined by a certain synergy or dissonance between the two components. So, it seems that we won’t get around the arduous task of individually testing (all possible) combinations to identify optimal SEL + I/O pairs, which is the eventual focus of this thread. I reckon a preparatory step can be to dig up all the hidden SEL and I/O treasures from this forum and beyond to see what inputs are available for the combinations.
Ultimate objective
Let's get rich together, why not?
Radu Spineanu
Derek Melchin thank you for this!
Simone Pantaleoni
My 2 Cents guys! :)
As starting point I've took the latest release published by Derek Melchin
Reviewed Coarse Selection of stocks - Improved Total Return, Drawdown and Sharpe
Enjoy it :)
Mark hatlan
Great work everyone! I took Simone's and did the following:
Drawdown is now down to -19% and annual return about double that at 38%.
Leandro Maia
Mark,
thanks for sharing your results. I just wanted to make a couple of comments.
First the indicator calculating the dollar volume average in the universe selection is not updating daily, but only when the algo is about do the rebalance. The indicator is also not being warmed-up.
Regarding the change in volatility timeframe, the self.lookback variable was supposed to be 126 and not 252. I think this was copy and paste mistake from someone, which used the other I&O algo.
The other place you changed the volatility was in the annualized volatility calculation, where sqrt(252) is used for anualization. To keep to code more understandable I would suggest you to keep 252 and instead apply a factor corresponding to sqrt(100) / sqrt (252) or 0.6.
Mark hatlan
Thanks for that Leandro, I didn't know the sqrt 252 was for annualized vol.
Peter Guenther
Derek Melchin, Simone Pantaleoni, mark hatlan, and Leandro Maia: Fantastic work there on the algo (SEL[EarningsRockets] + I/O[DistilledBear])!!
To add to our pool of stock selection strategies combined with I/O strategies: An old classic from Quantopian combining the “Quality Companies in an Uptrend” stock selection with the In & Out.
SEL[QualUp] + I/O[In & Out]
Chris Cain posted the original “Quality Companies in an Uptrend” strategy on Nov 22 2019 (Quantopian). It has seen some early tweaks which the attached algo builds on. The idea is to select high-quality stocks based on several fundamentals: (1) cash return, (2) free cash flow yield, (3) return on invested capital (roic), and (4) leverage. Basically, firms are ranked on each of these factors and these ranks are aggregated. There is a certain hierarchy: Factors (1) and (2) are combined first (i.e. sum ranks and calculate a new rank) into a value factor. The final quality factor results from combining the value ranking with the roic and leverage rankings.
Then the quality stocks are ranked according to their momentum and the top 20 stocks are bought.
Backtesting period: Jan 1 2008 to now
Total return: 3,597%
Sharpe: 1.25, Compounding annual return: 31.89%, Max drawdown: 33.00%
Some specifics regarding the selection process:
- start with the top 500 dollar volume stocks
- select the top 250 stocks according to the fundamentals ranking
- select the top 20 stocks based on the momentum ranking
Like SEL[EarningsRockets], SEL[QualUp] has the advantage that we do not need to commit to a certain sector (e.g. Tech) since the selection is based on fundamentals, giving all sectors an equal chance to make it into the final selection. The stock vector changes dynamically over time depending on which sectors/stocks are doing the greatest.
I still have to give Jonathon Tzu ’s modified QualUp a shot.
Leandro Maia
Follows another version of Distilled Bear with Stock Selection based on the findings of Mark.
Total return: 9532%
Drawdown: 23%
CAGR: 42%
Sharpe: 1.641
Peter Guenther
Great work there again, Leandro Maia and mark hatlan (and others)!
I performed the 'Damiano Bolzoni test' :) and removed TSLA from the universe (if you want to try yourself, see the attached backtest; lines 39-41 and 145-148). The returns are holding up quite nicely: 6,675.80% total return. Also the reduction to 5 stocks from 10 stocks in the final holdings vector holds up nicely. For 10 stocks the total return would be 3,222.34% i.e. 5 stocks perform better. Great stuff!
Peter Guenther
Returns also look good from the perspective of the annual saw tooth chart (see In & Out thread; here: versus holding QQQ). Of course, three years substantially contribute to the total return: 2008, 2010 and 2020. Anyway, the strategy (blue line) hardly underperforms QQQ (black line), only in 2009 and 2013. In all the other years you have overperformance. This looks very good!
Mark hatlan
Thats a cool returns chart, how did you display that?
As for the returns yes 2020 dramatically improves overall profitability. If you remove 2020 then you get around 2100% return, drawdown 20% and CAR 29%. Which still isn't that bad, mind that it still uses TLT instead of TMF.
Only other thought I have is to hedge the stocks with IEF, but in order to preserve profitability it needs to use margin for that hedge.
Peter Guenther
mark hatlan: Attached is an algo that includes the relevant code to create the chart. Feel free to just copy and paste the relevant code snippets since the algo also includes the TSLA test I preformed earlier:
lines 74-81: initialize a few variables for the chart(s)
line 244: call the chart function as part of the daily in/out signal check
lines 315-324: a few calculations for the saw tooth chart (Portfolio return vs QQQ return)
line 334: a variable that saves the current year. At year change (line 317) the base to calculate the return is reset, creating the saw tooth view.
Simone Pantaleoni
Great Stuff Peter Guenther Derek Melchin, mark hatlan, and Leandro Maia: ! This is rocking hard now with the latest changes! :D
I have another idea to include in the project, so let's keep posted! :D
Simone Pantaleoni
Here we go again. Is not the last release I've "promised", but I've seen somebody forgot to include the weekly volume based Coarse Selection I've posted out a few comments ago :)
Performance wise it improve Total Return, Sharpe heavily (up to 1.814), and also bring in a slightly lower Drawdown.
Leandro Maia
Simone,
in you implementation the price volume average indicator is being update only when the algo is about to rebalance and the universe selection is executed. So it's not a 5 day average, but the average of the last 5 times when rebalance happend. If you make it update daily you see that there's no almost no change in the results but the backtest takes much longer to run.
Simone Pantaleoni
Gotcha! Thanks for spotting it Leandro :) was early morning in my defense :P :)
Peter Guenther
Some quick findings to share:
When we have the In & Out underlying, the total return is at ~2,000%, so much lower. A stricter universe updating regime (4th Feb and then every three months) can get us to 3,300%. The universe updating timing appears to play a key role. It seems that updating less often (Distilled Bear) versus more often (In & Out, which is ‘out’ more often and then updates the universe before getting back in) leads to higher total returns. The DistilledBear generally appears to have the better timing in the backtest. I will have a look whether this is specific to the stock selection or can be generalized to other stock selections (e.g. QualUp).
Damiano Bolzoni
Peter Guenther is there a way you can share the latest versions of both Distilled Bear and In&Out versions? It's difficul to go back in the thread and find the "right one" :-)
Thanks!
Damiano Bolzoni
In general, for momentum-based strategies rebalcing once a month is optimal. So I would change the 60-day rebalancing baked in right now. Furthermore, it is well known that the date picked for rebalancing can have huge influence n the returns ("timing luck"). Rebalancing at the very beginning of the month bears higher returns compared to middle of the month. I never found a reliable explenation, I would say it's because the big funds will rebalance around the end or beginning of the month.
https://blog.thinknewfound.com/2015/04/new-research-paper-minimizing-timing-luck-portfolio-tranching/Peter Guenther
Damiano Bolzoni: Thanks for your comments!
Attached is an algo that includes both the In & Out and Distilled Bear algos, with a switch in line 55 (self.go_inout_vs_dbear set to 1 vs 0). The ‘engine rooms’ of the in & out algos are the signal checks which are sitting in the functions def signalcheck_inout(self) and def signalcheck_dbear(self), respectively. This set up may allow to efficiently compare ‘in & out plus stock selection’-combos.
The stock selection strategy is the Valuation Rockets (slightly relabelled compared to earlier since the selection is mainly based on a valuation multiplier plus momentum).
It also includes the saw tooth chart (Portfolio vs QQQ; lines 377-381), which I recoded a bit to make it more compact.
I have replaced the leverage line with a chart showing the cash level (settled and unsettled). We want to avoid going into the negative territory here (for an unleveraged play) and reduce the amount of unused cash.
Peter Guenther
Regarding the actual results of the previous post’s attached algo: It shows that by merely switching the in & out logic between the two in & out algos which yield similar results when holding the SPY or QQQ (In & Out thread), the total return goes from about 9,000% (Distilled Bear) to 1,500% (In & Out). Open for discussion: This sensitivity may be a warning sign regarding very lucky timing in the Valuation Rockets & Distilled Bear combo (esp. the timing of the universe reshuffle)? I mean, I could still imagine to trade the combo but possibly not with the weight I initially planned to. Any thoughts/something that I am not seeing?
Peter Guenther
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!