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?
Peter Guenther
Following up and, again, open for discussion: For the ‘Quality Companies in an Uptrend’ stock selection (QualUp), the results of the in & outs are markedly closer together which is somewhat comparably reassuring?
Additional thought: The ‘annual saw tooth chart’ shows that the in & outs have their excess returns at different points in time. Could this be a rationale for mixing the two logics and trade them 50-50 in terms of being 100%, 50%, or 0% ‘in’/’out’?
SEL[QualUp] + I/O[In & Out]:
SEL[QualUp] + I/O[Distilled Bear]:
Derek Melchin
Hi Peter,
Yes, that could be a rationale for looking into mixing the strategies together. Consider calculating the correlation of daily returns between the two strategies. Combining non-correlated return streams may increases profits and reduces drawdowns over the backtest period.
Best,
Derek Melchin
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.
Juhwan Kim
hello,
I found something strange in the script.
# Filter the values of the dict: we only want up-trending securities
values = list(filter(lambda sd: sd.smaw.Current.Value > 0, self.averages.values()))
smaw is simplemovingaverage which is showing stock's average price within certain periods.Therefore, to my understanding, this line of code filters every stocks since stock price should be more than 0?
and following line,
values.sort(key=lambda x: (x.smaw.Current.Value), reverse=True)
#values.sort(key=lambda x: (x.volume_ratiol), reverse=True)
# we need to return only the symbol objects
return [ x.symbol for x in values[:self.num_coarse] ]
These will filter the most expensive stocks in order.
Can please someone answer my question?
Chak
Juwan, smaw should be for volume, not for price.
Juhwan Kim
Chak, can you explain more detail why? Sma does not consider volume.
Dimitar Dimitrov
Hi Guys,
First, let me tell you that you are doing great work here, please keep it up.
As I am based in the EU and have an account with IB here, I am not allowed to trade TLT or any other US ETF. As QuantConnect does not facilitate the trading of European ETFs, I am trying to find a workaround. Here is what I intend to do:
1. Use this algorithm to generate the stocks universe and trade them automatically on QC(IB).
2. Once the signal switches from be_in to be_out, it should generate an email, notification for me to trade the European equivalent of TLT (IS04.DE). I will do the trading manually.
3. After the signal switches back to be_in then it should liquidate the IS04.DE position. I want to use self.Liquidate() to close all open positions, before the algorithm does the rebalancing and enters into stocks again.
# Liquidate the Bond Position before buying the stocks if self.be_in and not self.be_in_prior: self.Liquidate()
Can anyone here tell me, if self.Liquidate() will also close out positions that I have opened manually in IB Trader Workstation?
Anyone here faced the same issues trading from the EU. Maybe there is a more elegant and automated solution?
Derek Melchin I saw some discussions from 2017, where QC staff were promising to allow trading of Non-US instruments and also IB CFDs. Is this coming anytime soon?
Many thanks!
Dimitar
Peter Guenther
Dimitar Dimitrov, thanks for joining in and I have to say: that would be amazing to develop an equivalent for European shares!
[side note: Regarding trading US shares at IB, couldn't you just exchange USD, sign their declaration to trade US shares (incl. tax residency) and go for it? You might just have to add the US market to your trading permissions. Of course, being located in Europe, you would then have the exchange rate risk, but that might be still OK in the USD/EUR pair.]
Dimitar Dimitrov
Peter Guenther thanks for your reply. Actually, the Issue is not in trading the stocks' selection. I can trade US Stock at IB and this what I intend on doing. The problem is with trading the Bond Leg as TLT is not available for trading in the EU. It is a regulatory restriction due to the KID rules. There is a European ETF that also tracks the performance of the 20+ Year Treasury bonds (IS04.DE), but unfortunately, QC does not support trading for this instrument.
If someone knows how the self.Liqidate() behaves it will be great.
In general, I totally agree that this strategy should also be tested on other markets to make sure that there is not overfitting to the US historical data. Therefore, I asked the QC team, when they intend to allow trading for other Non-US markets.
Alternatively, if someone has data we could try and implement a Custom Data source at least for the backtest.
https://www.quantconnect.com/docs/algorithm-reference/importing-custom-data#Importing-Custom-Data-Tiingo-Price-DataPeter Guenther
Got it, that's good to know, Dimitar Dimitrov! Regarding your question, self.liquidate() would sell everything, i.e. also the non-algo holdings you have in the account. I found this thread here:
https://www.quantconnect.com/forum/discussion/644/how-does-liquidate-behave/p1I reckon the safest way is to open an additional linked IB account for the algo (via Account Settings). The link enables easy funds transfer between the accounts.
Primoz Golle
Hello guys,
Firstly I would like to thank all of you for contributing your knowledge to this community. As a beginner, I have learned a lot reading this topic.
As I come from Europe I have the same issues as Dimitar. I have found this link: https://logical-invest.com/pripps-and-kid-compliant-etfs-for-european-investors/, which says SPY and GLD are also forbidden for Europeans to trade. Is this correct?
Thanks for your help once again!
Dimitar Dimitrov
Hi Primoz Golle
Yes all of those instruments are not available for trading in Europe. The link that you shared is the regulation that requires KID which the US ETF providers don't support. For all of them you can find equivalents traded on the European exchanges, but QC does not support those yet. However, in this strategy you are not trading the ETFs, you only use them for signal generation. You can trade the stocks using QC, for TLT I am still trying to find a solution.
I hope this helps.
Best regards,
Dimitar
Fabmei
Hello Dimitar,
may I ask which country you reside in? Generally IB provides access to US exchanges and you can trade TLT, this is not an issue with regulation afaik (for me as a german resident at least). Have you checked your account settings / trading permissions?
Best, Fabmei
Primoz Golle
Dimitar, thanks for detailed explanation. Fabmei, thanks for remark, i will check with the IB. Probably the same rules should apply to the trading of natural persons of all eu residents, if I'm not mistake?
Dimitar Dimitrov
Hi Fabmei
Thanks a lot for the tip. That is strange! I am based in Germany as well, but IB Support told me that I it is not available for trading in Germany. Do you also have an IB PRO Account?
I'll just try and buy 1 on my live account, to see if they are going to execute it or not.
Best, Dimitar
Alexandre Catarino
Hello everyone!
Since this thread and algorithm are popular, let me make some considerations to help those who are considering putting their money on the line.
Scheduled events work slightly differently in live and backtesting mode. While backtest is purely data-driven, scheduled events are triggered by the clock in live mode. So, if the scheduled event is set to fire at 10 am, it will fire at 10 am o'clock. On the other hand, hourly data will be synchronized into the Time Slice a few milliseconds later, e.g. 10:00:00.0123. Consequently, CurrentSlice might not have the market information and CurrentSlice.ContainsKey(symbol) with return false for most if not all symbols.
In order to address this issue, we can use minute resolution data or set the scheduled event to 10:01. I suggest using minute-resolution data. Please keep in mind that minute-resolution data is L1 so orders will be filled at the bid/ask and backtest will be more realistic.
Additionally, we can remove the CurrentSlice.ContainsKey check, since we are getting the price from Securities[symbol].Price. In principle, this variable is not zero for liquid assets with minute resolution data.
I would recommend adding strategic logging to the algorithm in live trading. When we deploy an algorithm for the first time, it will help us understand why it's not working as expected. Since there is a daily quota limit in backtesting but not in live mode, we can use the following method to only log in live:
def LiveLog(self, message): if self.LiveMode: self.Log(message)
Peter Guenther
Really great pointers. Thanks for sharing these hints with us, Alexandre Catarino!
Strongs
Peter Guenther
Thanks for sharing, Strongs. Your post just brought up a thought that I think might be worth re-emphasizing (you also mention aspects of it): The ValuationRockets selection (on EV/EBITDA) means to select stocks that are extremely highly valued against the background of their earnings: The smaller the (positive) earnings a company generates, the higher the EV/EBITDA. Of these firms, we select the ones whose stock prices were increasing the fastest (the momentum logic). Think: we hype the hype. This is a high risk strategy, considering that something that is valued very highly might have a lot of room to drop. In comparison, for example, the QualUp stock selection is lower risk (and probably lower return in the long run). Due to the recent market/tech drawdown, the QualUp selection has performed better year-to-date than the ValuationRockets selection. Of course, this is only a current snap shot and we'll have to see what the year still has in store:
ValuationRockets: -16.2% <--------> QualUp: +21.4%
Biggleswurth
Biggleswurth
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!