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
(Simplified) Demonstration of concept: SEL[“QQQ”] + I/O[“In & Out”]
In the following backtest, I combine a simple tech stock selection strategy, via buying the QQQ ETF, with the 3 Nov 2020 version of the “In & Out” strategy, which is one possible in & out-type tactic (see the In & Out thread for more tactics; link above). The backtest is from 1 Jan 2008 to 30 Oct 2020. The total return is 1,723%.
The components seem to integrate nicely: the QQQ alone (no in & out) would have yielded about 515% during the backtest period, while the In & Out strategy without a tech selection (only holding the market, SPY) would have resulted in about 1,100%.
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.
Peter Guenther
And an additional (simplified) application, combining a yet more specific tech stock selection, the semiconductor industry, with the In & Out algo. Below are the specs for the same backtest period as above.
SEL[“SOXX”] + I/O[“In & Out”]
Total return: 1,686%
SOXX alone (i.e., always in): 559%
Implications
The In & Out combines slightly better with the QQQ selection (see above) than the SOXX selection, improving the returns from 515% to 1,723% versus from 559% to 1,686%.
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.
Nathan Swenson
Just messing around with Flex4 QQQ version. Changing TLT and IEF to TMF and TYD pumps results up to 3539% return.
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.
Peter Guenther
Nathan Swenson: Absolutely, and great point! If we really trust our strategy, leveraged products, such as the 3 x leveraged bond ETFs, can substantially boost returns. In the attached backtest, I have taken it one step further and used 3 x leverage for all holdings, the 'in' side and the 'out' side. Of course, one would not put all the money on a highly leveraged strategy like this. The max drawdown is 50%+, so this can be psychologically quite distressing. It may be something for a (small) portion of one's total investment, if one feels comfortable with leveraged products.
3 x leveraged SEL[“QQQ”] + I/O[“In & Out”]
'In' holdings: TQQQ
'Out' holdings: TMF, TYD (as per Nathan's test above)
Total returns: 21,882%
Note: The In & Out is the latest 'lazy trader edition', reducing the total number of trades from above 3,000 (see in the QQQ version above) to 207 ... 207 glorious trades to get us to the 20,000%+ :)
As always, for details regarding the latest versions of I/O strategies, see our discussion here.
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.
Nathan Swenson
Wow! Well, I wouldn't likely use TQQQ due to the decay, For bonds, my thinking is that holding period is shorter and they should be less volatile resulting in less decay. Anyway, that was my thinking. Those results are amazing!
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.
Matthew Wormington
Per comments made in the other "In and Out" thread, perhaps the risk-off asset selection is at least as critical as the risk-on asset selcetion to provide good performance in the future.
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.
Mateusz Pulka
Peter Guenther
If may I ask about your last algo.
You set symbol for long order:
self.HLD_IN = {self.STKS: 1}
but in the code when you want to send an order to market you have:
wt[self.MRKT] = 1
Is it a mistake or is it right? Cause HLD_IN parameter suggests that here you should have:
wt[self.STKS] = 1
By the way:
Great work with algorith.
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.
Joshua Tsai
You can use TIPS instead of bonds (to slightly reduce returns, but it's widely applicable). Then again, the US gov's only option during bad economic times is to lower rates, and it's very unlikely the Fed would decrease rates as a section of the economy was faltering. I've also looked into going long volatility during market downturns, but it hasn't worked well.
I've attached the global ETF rotation strategy that was modified from the tutorial one on Quantconnect.
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.
Peter Guenther
gpw radar Thanks for joining this thread and well spotted! This looks like a bug from combining the In & Out with the QQQ stock selection; will post an update soon.
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.
Joshua Tsai
Using TIPs we achieve similar returns, but the Sharpe is much worse.
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.
Peter Guenther
Corrected: 3 x leveraged SEL[“QQQ”] + I/O[“In & Out”]
'In' holdings: TQQQ
'Out' holdings: TMF, TYD (as per Nathan's test above)
Total returns: 15,438%
Not quite the 20,000%+, still some way to go :)
Thanks to gpw radar for spotting a bug in the earlier code which I think resulted in holding the SPY and TQQQ in parallel, i.e. on margin / leveraged. In future editions, I will try and record the leverage so that similar issues pop up quickly,
At least the max drawdown also decreased from 50%+ to 40%+, still quite steep of course.
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.
Peter Guenther
@Joshua Tsai: Thanks for sharing these results regarding TIPs, a long volatility strategy, and the ETF rotation outline. Much appreciated and great thinking!
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.
Tien Duy Vo
Thanks for sharing the code. I used your last version ( Corrected: 3 x leveraged SEL[“QQQ”] + I/O[“In & Out”] ) in a small backtest from 2019-now. However, based on the orders I can not see any "In" or "Out" orders. The strategy buys TQQQ, TMF, and TYD and sells it in the same time frame. Despite all this, the performance looked good. I still wonder whether this was intentional.
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.
Nathan Swenson
Based on corrected version and only using TQQQ and TMF, no TYD.
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.
Nathan Swenson
Almost qualifies for competition with nearly 80% alpha score. Pretty tough for anyone to beat 23000% return over this period!
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.
Nathan Swenson
Large drawdown of course, but otherwise good numbers.
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.
Tien Duy Vo
Nathan Swenson Which version did you used? Did you checked the orders?
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.
Peter Guenther
Great series of tests there Nathan Swenson, thanks for sharing! You cracked the 20,000% again, nice :)
Tien Duy Vo: Thanks for joining the discussion! I am not 100% whether you looked at the order data below, this is from the Corrected algo version above running from 1 Jan 2008 to today. I have copied in a part of 2019. What should be happening is that the algo alternates between holding the leveraged bond ETFs (TMF and TYD) versus holding the leveraged tech stock selection (TQQQ). For example, see the first lines with the negative quantities (-70701 and -29249): it's selling the bonds on 18 Jan 2019 which it was holding before. In parallel, it's buying the TQQQ (see positive quantity 55093). Then on 24 Jun 2019, it's selling the TQQQ quantity (-55093) and it's investing the money in the bonds (see positive quantities). So, the algo sometimes holds the TQQQ and sometimes the bonds, based on the in & out indicator (see the variable self.be_in in the code). Not sure whether this answers the question?
(Sidenote: there are some "invalid" entries in there, were it doesn't seem to be able to get a price for TQQQ. However, this doesn't seem to affect the holdings.)
Time Symbol Price Quantity Type Status Value Tag 2019-01-18T16:30:00Z TMF 18.09502674 -70701 Market Filled -1279336.485 2019-01-18T16:30:00Z TYD 41.89420637 -29249 Market Filled -1225363.642 2019-01-18T16:30:00Z TQQQ 45.31716207 55093 Market Filled 2496658.41 2019-06-24T15:30:00Z TQQQ 63.66676589 -55093 Market Filled -3507593.133 2019-06-24T15:30:00Z TMF 24.64069751 71190 Market Filled 1754171.256 2019-06-24T15:30:00Z TYD 50.32595584 34820 Market Filled 1752349.782 2019-09-06T15:30:00Z TQQQ 64.62641568 65562 Market Filled 4237037.065 2019-09-06T15:30:00Z TMF 32.36969776 -71190 Market Filled -2304398.783 2019-09-06T15:30:00Z TYD 55.32687056 -34820 Market Filled -1926481.633 2019-09-11T15:30:00Z TQQQ 64.55644122 -65562 Market Filled -4232449.399 2019-09-11T15:30:00Z TMF 29.42790146 71810 Market Filled 2113217.604 2019-09-11T15:30:00Z TYD 53.32674448 39628 Market Filled 2113232.23 2019-11-01T15:30:00Z TQQQ 0 59469 Market Invalid 0 2019-11-01T15:30:00Z TMF 28.76884979 -71810 Market Filled -2065891.103 2019-11-01T15:30:00Z TYD 53.35052892 -39628 Market Filled -2114174.76 2019-11-01T15:30:00Z TQQQ 70.48427795 59269 Market Filled 4177532.67 2019-11-05T16:30:00Z TQQQ 72.61350093 -59269 Market Filled -4303729.587 2019-11-05T16:30:00Z TMF 26.83698518 80200 Market Filled 2152326.211 2019-11-05T16:30:00Z TYD 51.835342 41577 Market Filled 2155158.014 2019-12-06T16:30:00Z TQQQ 0 56469 Market Invalid 0 2019-12-06T16:30:00Z TMF 27.60375618 -80200 Market Filled -2213821.246 2019-12-06T16:30:00Z TYD 51.82537367 -41577 Market Filled -2154743.561 2019-12-06T16:30:00Z TQQQ 77.21182285 56515 Market Filled 4363626.168
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.
Tien Duy Vo
Peter Guenther : Thanks for the clarification. You are right. If I start the algo on 01/01/2008, I get the same result as you have posted. However, if I start the algo on 01/01/2018 then I get these results.
Fill: $48.15361309433875 USD
2071Filled +2018-01-02 11:30:00TMFBuy MarketFill: $20.750885826 USD
2404Filled +2018-01-02 11:30:00TYDBuy MarketFill: $42.892753618 USD
1158Filled +2018-01-05 11:30:00TMFSell MarketFill: $20.760609765 USD
-2404Filled +2018-01-05 11:30:00TYDSell MarketFill: $42.60804548 USD
-1158Filled-2018-02-02 11:30:00TQQQSell MarketFill: $55.87096473697939 USD
-2071FilledThe 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.
Nathan Swenson
Ok, I see that this strategy works much better with SPY derivatives rather that NQ. Just switching over to SPXL in tandem with TMF (no TYD) I get nearly 40,000% return:
https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_3f192d90a6cb21b1968829b75efdb63f.htmlThe 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.
Nathan Swenson
I'm thinking to set up the live trading, but to use it with paper trading just to get the signals in real time. I guess it would be better if it alerts ahead of time, like at open that there will be a trade at 2 hours after open. Because this strategy has so few trades, it's easy enough to just do the trades manually. I'm thinking I'll use a small amount in futures to trade NQ and ZB pair and my TD Ameritrade self managed 401k with a more conservative setup.
Regarding the Alpha Competition, this version qualifies with 84% PSR (Alpha score). Peter, you should think about entering it. You did all the work. I'm just playing around with for consideration of using for my own accounts.
Regarding the high results above, that was without any Margin. So if you wanted to go crazy, you could add some margin to it, or simply trade non-Leverage funds but lean more on margin.
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.
Nathan Swenson
Screen shot of the end result.
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.
Nathan Swenson
Sorry for all the posts. Having trouble posting screen shots when working from an IPAD.
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.
Mateusz Pulka
Tien Duy Vo Peter Guenther
I have spotted this bug also, the problem is here (the loop is run outside the if statement):
if not self.be_in:
# Close 'In' holdings
#for asset, weight in self.HLD_IN.items():
# self.SetHoldings(asset, 0)
#for asset, weight in self.HLD_OUT.items():
# self.SetHoldings(asset, weight)
wt[self.STKS] = 0
wt[self.TLT] = .5
wt[self.IEF] = .5
# Thomas's reducing unnecessary trades
for sec, weight in wt.items():
cond1 = (self.Portfolio[sec].Quantity > 0) and (weight == 0)
cond2 = (self.Portfolio[sec].Quantity == 0) and (weight > 0)
if cond1 or cond2:
self.SetHoldings(sec, weight)
The for loop will be fire every time even if we set self.be_in to false. The correct version is:
if not self.be_in:
# Close 'In' holdings
#for asset, weight in self.HLD_IN.items():
# self.SetHoldings(asset, 0)
#for asset, weight in self.HLD_OUT.items():
# self.SetHoldings(asset, weight)
wt[self.STKS] = 0
wt[self.TLT] = .5
wt[self.IEF] = .5
# Thomas's reducing unnecessary trades
for sec, weight in wt.items():
cond1 = (self.Portfolio[sec].Quantity > 0) and (weight == 0)
cond2 = (self.Portfolio[sec].Quantity == 0) and (weight > 0)
if cond1 or cond2:
self.SetHoldings(sec, weight)
The same should be applied in second if statement.
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.
Mateusz Pulka
Sorry some kind of formatting problem. Generally the for loop should be move inside the if statement as Tien Duy Vo pointed out when algo starts and be_in paramter is true we will buy long and short at the same time.
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.
Nathan Swenson
I'm sorry, I don't know Python. I don't see any difference between your code blocks. Is this mistake resulting in inflated results due to margin usage?
Edit: Didn't see your last response. I will wait for a Python coder to update it. I only know C#.
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.
Mateusz Pulka
Sorry for formating problem. The code should look like this:
https://pastebin.com/cnKm9BVYinstead of this:
https://pastebin.com/pPcGFKR0The 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.
Nathan Swenson
So the issue pointed out by Gpw radar and Tien Duy Vo only occurs if "be_in = true" at the time of start. I don't see any issues with my order when ran from 2008 to 2020. It would seem that the results for mine are correct. I was worried that the results were invalid.
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.
Tien Duy Vo
gpw radar : Thanks for pointing out. Great job. Unfortunately, the backtesting framework on Quantconnect seems to be much slower than on Quantopian. It is quite difficult to debug that way.
There is another issue related to this part of the code:
self.Schedule.On(
self.DateRules.EveryDay(),
self.TimeRules.AfterMarketOpen('SPY', 120),
self.rebalance_when_out_of_the_market
)
self.Schedule.On(
self.DateRules.WeekEnd(),
self.TimeRules.AfterMarketOpen('SPY', 120),
self.rebalance_when_in_the_market
)
Here, the algo is firing the two functions rebalance_when_out_of_the_market and self.rebalance_when_in_the_market, which is responsible to get "in" and "out". However, you can see that one is started every day and the other one at weekend. I wonder, whether this is done on purpose.
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.
Mateusz Pulka
You are right Nathan Swenson it only occures once at the begining when you start algo and when flag in is set to true. For example check out your orders when you set the star date at 1st January 2018. It is not a big deal but worh to fix it.
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.
Mark hatlan
Great work! This market timer does a really nice job.
However TQQQ does do way better than SPXL. SPXL starts on 11/03/2008. UPRO starts on 6/28/2009. TQQQ starts on 2/7/2010. When switching the start date to 2/7/2010 here are the returns:
SPXL +7,552%
UPRO +7,180%
TQQQ +19,859%
I think SPXL only looked better because of the earlier first trade date.
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.
Nathan Swenson
Thanks Mark! Good point!
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.
Aalap Sharma
Relativily new to all this and I would really like to know are these returns realistic in the real markets? Has anyone deployed such algos to the market and seen healthy returns. Just curious...
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.
Nathan Swenson
Aalap, I just turned the algo on and entered TMF. We shall see soon enough. I'm going very aggressive with leveraged products. It should be very realistic as it only trades about 10 times a year with trades just 2 hours after RTH market open. Algo is entirely in treasury bonds at the moment.
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.
Aalap Sharma
Cool! I was thinking the same :)
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.
Mateusz Pulka
Hi Guys,
I have added some improvments to the code and please noticed the result. So first algo has improvment in terms of open the trade at the begning of the cycle when we start the algo. The return for 2010-2020 is: 16 772%
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.
Mateusz Pulka
The second run contains the following improvement. I just want to generate a signal about in/out just right after the open market. But open position just in the same way as the original algo. What is surprising the result is 21 011%. I am a little bit surprised about this, to be honest. Any idea where this difference comes from?
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.
Nathan Swenson
Gpw Radar, I see it takes more trades when you check signal at open. Perhaps it's due to increased volatility at open which is more likely to trigger needed deviation. The 2 hours after close is actually European market close for which there is often a ramp up in index price. I had thought about messing around with that as even 5 minutes makes a difference in that period. I know 2hrs and 5 min is significant. The timing of entry vs exit and asset type all matter. Bonds seem affected more at open, mid day, and close, while 2hr after open seems more significant for equities. Lots of opportunity for improvement I believe with timing alone.
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.
Mateusz Pulka
please notice that I only generate a signal in/out 1min after the market is open and then after 120min I open the position base on the signal. I have noticed that as I used IB with the cash parameter some of the orders were not filled (lack of money) and the order was later sometimes even 5 days later.
Peter Guenther Have you tried to use futures instead of etf to generate the in/out signal?
https://finance.yahoo.com/commodities?.tsrc=fin-srch
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.
Nathan Swenson
Gpw, perhaps the delayed order in due to transaction order. I often see that the buy order is executed before the sell order for prior holdings. This probably needs to be fixed.
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.
Peter Guenther
gpw radar: Futures are a good idea and are likely to improve performance. Tentor (see In & Out thread and Quantopian archive) used futures on Quantopian and could improve the algo's total returns. However, see the discussion in the In & Out thread regarding that implementing this futures strategy is very tricky on QC.
Nathan Swenson: Great point. Probably we need a code snippet forcing the sell orders to be executed first, i.e. for those stocks whose weights are positive in the current holdings but zero in the new holdings. Then, ideally, the algo would wait for a complete sell confirmation before it goes on to the purchases. Currently beyond my coding skills to implement this -- I only can say that you made a great point there and I am hoping that others might have a suitable code to implement the idea :)
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.
Nathan Swenson
Regarding the warm up necessity, we will know once the next IN signal comes. I currently have the WarmUp line commented out, but haven't Peter's edit to avoid immediate entry at start. I will compare my live version to the backtest to verify it's correct. I'm currently in TMF from 34.10 (current price 36.24).as compared to Algo's entry of 37.06 on 10/6/2020 as noted in backtest log. I was lucky with my entry, catching the bottow (so far). This will give me some cushion once I make the switch into TQQQ.
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.
Aalap Sharma
Nathan Swenson did you deploy it on the quantconnect paper trading platform and did you get a error due to large warmup period? I deployed it on Friday after close and havent seen any errors yet. I guess it will happen tomorrow once the market opens.
I also added a snippet to email alerts to a google group, lets see if that works.
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.
Nathan Swenson
Aalap Sharma,
I have the warm up declaration commented out on the version I'm running. I haven't tried the latest version, but was necessary to comment out on prior version for it to run.
I am running it live with paper trading and just use signals to manually trade my accounts.
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.
Peter Guenther
Aalap Sharma and Nathan Swenson: Great discussions about implementing this for live trading, keep it going and good luck with the investments :)
Just to continue with the test series, I was running a different stock selection that Joseph Kravets mentioned: a momentum stock selection (via the MTUM ETF). Attached are the findings. My feeling is that the In & Out may not combine that well with a momentum strategy, but of course more tests are needed to fully assess this.
SEL[“MTUM”] + I/O[“In & Out”]
Total return: 368%
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.
Peter Guenther
And a disruptive innovation selection that Joseph Kravets has suggested. I reckon with this and the MTUM above, we have to factor in that these ETFs were started past 2008, which is 'depressing' returns in the backtests. Later, I will try to post a comparison with QQQ for comparable timeframes ... and then a question also is how we think the future will look like (vs how the past looked like = backtest results).
SEL[“ARKK”] + I/O[“In & Out”]
Total return: 543%
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.
Peter Guenther
Quite interesting! To benchmark the prior two posts:
MTUM: It seems that MTUM started in April 2013. From 1 Apr 2013, the SEL[“QQQ”] + I/O[“In & Out”] generated 213%. Thus, the 368% return of the SEL[“MTUM”] + I/O[“In & Out”] combo outperforms. Forget what I said above regarding the In & Out not combining well with a momentum stock selection strategy. This finding is more in line with what Jonathon Tzu wrote in the "Quality Companies in an Uptrend" thread:
<<Peter Guenther I've actually found that the In and Out Strategy from Quantopian meshed very well with returns (nearly tripling returns over 18 years, the length of the backtest).>>
ARKK: The ETF seems to start in Nov 2014. From 1 Nov 2014, the SEL[“QQQ”] + I/O[“In & Out”] generated 172%. Thus, the 543% of the SEL[“ARKK”] + I/O[“In & Out”] combo clearly outperforms.
It seems like we have to reshuffle our portfolios again. Kudos, Joseph Kravets for the tip :)
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.
Nathan Swenson
Peter, that's great! Now if we could improve "Out" holdings. The largest draw downs are in Bonds at least for my aggressive setup with TQQQ and TMF. There I see a 49.9% draw down. Not so easy to overcome that other than using a less aggressive funds and sprinkle in some Gold.
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.
Joseph Kravets
@Peter Guenther In my view you could select between arkk, mtum, and a quality and value etf to see which style is best that year. Arkk is what i would call a "yolo etf" , like what people on wall street bets would buy. maybe in the future value outperms momentum, who knows. You can do a portofolio optimization between the different factor etfs. Also just holding bonds is simplistic, you can have another strategy that outperforms in bear markets, such as trend following currencies/commodities/forex/maybe crypto. trend following does best in bear markets and always adapts. we dont know that bonds will do well if interest rates go up.
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.
Joseph Kravets
I use breakouts on 40 different futures markets. it did very well during the covid crash. you can combine this with the in and out but its complex.
https://qoppac.blogspot.com/2016/05/a-simple-breakout-trading-rule.html
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.
Pcnpj
Ah, nevermind. Seems like trading economics was discontinued.
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.
Goldie Yalamanchi
Vladimir
So I have renamed the filters as Fundamental and Momentum filters and I believe I did have them in the order you suggested. Momentum then fundamentals.
self.AddUniverse(self.MomentumSelectionFunction, self.FundamentalSelectionFunction)
Anyways I have added a short backtest here one more time to go thru the code. Yes I don't understand that initial TLT symbol error either. I may need some help to clean up this code (I did remove some more unused items). Yes I think your mention of the leverage it sometimes exceeds 1.0 and gets as high as 1.2 and in the beginning maybe for that reason it has a 20% drawdown in Sept-Oct.
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.
Goldie Yalamanchi
Vladimir
So I have renamed the filters as Fundamental and Momentum filters and I believe I did have them in the order you suggested. Momentum then fundamentals.
self.AddUniverse(self.MomentumSelectionFunction, self.FundamentalSelectionFunction)
Anyways I have added a short backtest here one more time to go thru the code. Yes I don't understand that initial TLT symbol error either. I may need some help to clean up this code (I did remove some more unused items). Yes I think your mention of the leverage it sometimes exceeds 1.0 and gets as high as 1.2 and in the beginning maybe for that reason it has a 20% drawdown in Sept-Oct.
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.
Peter Guenther
A quick one to share: I reimplemented an earlier 'for fun' algo (here in a leveraged version) that capitalizes on the strong run up in the silver price after significant market drops. The play (particularly lines 127-135): after the market has dropped by 30% or more and when the In & Out says 'in', we invest in double leveraged sliver (AGQ) until the market has approx. (within 1.5%) recovered to its pre-drop level. So here it is: the In & Out with a silver fountain :)
SEL["TQQQ" VS "AGQ"] + I/O["In & Out"]
76,000%+
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.
Radu Spineanu
Nathan Swenson Trying to deploy it with paper trading as well and running into "Runtime Error: Execution Security Error: Memory Usage Maxed Out - 512MB max, with last sample of 1049MB." Which plan are you using? Or what are some tricks tot make it more efficient?
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.
Vladimir
Goldie Yalamanchi,
Sorry, I just now realised that Peter Guenther changed his definition of superior stock selection to leveraged ETF.
I have published your strategy here.
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.
Peter Guenther
Goldie Yalamanchi and Vladimir: happy for you to add the Qual-Up conversation here if that would be of interest. True, we branched off a bit into the area of leverage. But the main question still is which stocks to select and combine with which in & out tactic. Leverage is just a multiplier of these choices, really. The key is that the underlying SEL + I/O choice is solid.
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.
Goldie Yalamanchi
Thanks Peter Guenther for the confirmation. Yes as you may know, I have been trying to run this against real $$$ as may be others. I do have concerns about all the concentration of SEL into tech stocks -- I just don't know if that bubble will continue so I thought in another basket let me try to use the Qual-Up strategy presented on this forum as a hybrid. Yes, due to the very nature of the IN/OUT even the Qual-Up SEL stocks do very well.
That said, one thought is that sometimes, IN/OUT is a bit early (Feb 2020 pre-Covid) or very late (Aug 2018 - Nov 2018). The latter one there is like a 25% drawdown (depending on the leverage instrument or SEL) is a bit harsh.
Can anything be done to improve that -- I know if we overly tune the shifts of the indicator pairs instruments noise may be introduced and the algo may not work well. But just considering somehow to improve that without "overfitting".
Someone suggested some other thoughts, I have added a few in the list.
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.
Guy Fleury
@Peter, great work. You must know that you can push your trading strategy much higher. Changed a few things, but mostly raised the initial capital to $1M and raised the leverage to 1.2x. Not excessive, but nonetheless, productive. Added leveraging expenses would be more than covered by the added profits. The following chart does suggest that it can be done.
You could push a little more, and more than double or triple the outcome. It is a matter of choice and risk tolerance. Regardless, seeking more volatility by using leveraged ETFs will bring slightly higher drawdowns. However, knowing that they will be there, using this leveraging will force us to design better and more sensitive protective measures and better switching procedures.
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.
Peter Guenther
Guy Fleury: Holy Guacamole, thanks for sharing! :)
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.
Peter Guenther
Radu Spineanu: Welcome back to the discussion! The data-consuming line is self.SetWarmUp(timedelta(350)) in the algo's initialization section. If you reduce this, e.g. to self.SetWarmUp(timedelta(100)), I reckon this should get you past the runtime error.
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.
Radu Spineanu
Thanks Peter Guenther ! Great to be back. Still trying to wrap my head around QuantConnect.
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.
Derek Melchin
Hi Peter,
To assist with development of this algorithm, I've added a manual warm up and consolidator for the lookback window. This improves the execution efficiency as we avoid daily calls to the History method.
I've also replaced the histshift calculation to utilize the built-in roll∈g Pandas method.
Lastly, a new condition has been added to the trade method to ensure the algorithm has current market data before placing a trade. This removes an error message that's present in the previous implementation.
See the attached backtest for reference.
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.
Peter Guenther
Derek Melchin: This is pure magic! Thanks so much for fundamentally overhauling the algo's data engine :) The efficiency gain, I am sure, will be appreciated by everybody using this algo in some capacity (optimization, trading, testing etc.). Very nice work!
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.
Nathan Swenson
So the strategies last trade was on Oct 6th into bonds (I entered mid cycle on Nov 9th). There has not been a trade since. I would assume there must be a signal that is keeping the IN from firing. I have watched the price go up to nearly 15% gain only to come all the way back down. Perhaps there should at least be a very loose trail stop of some sort. It really sucks to see all gains evaporate like that. I was tempted to exit manually as this is real money, but want to stay in sync with the algo.
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.
Nathan Swenson
Anyway, I know this is a long term type strategy, but I'm tempted to try messing around with a 35 period Linear Regression type trailing stop or 20EMA on the hourly to check closes against in case of trending price. I'll have to test this in NinjaTrader as I just don't know the tools/indicators on this platform as well.
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.
Radu Spineanu
I've tried in/out with quality momentum stocks and I'm seeing a similar thing to Nathan, last entered in Oct. This is the code.
Derek Melchin do you spot anything obviously wrong?
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.
Vladimir
Radu Spineanu,
Did you have a chance to complete the full backstest (self.SetStartDate (2008, 1, 1))
of this strategy in the last 4 days?
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.
Guy Fleury
@Derek, sorry to raise the following but I have some issues.
ARKK starts trading in 2014. Therefore prior to that date, trades are only on the TLT and IEF bond ETFs (first 6 years of the strategy). It kinds of defeats the notion of switching to bonds prior to 2014 since the strategy could only be in bonds in periods identified as “out”.
From 2014 to 2017, ARKK traded on average less than 10k shares per day. Some days with 100 shares! Therefore, that also kind of defeats the switching to stock gambit. It is only this year that the stock's price and volume really surged. Meaning that prior to 2020, the strategy might have days where its market orders would have exceeded the daily traded volume or took a large chunk of it.
My point is no one in 2008 would have chosen ARKK as the sole long candidate for their long-term portfolio since it was not even available. And most probably, only a few individuals would have done so after its 2014 debut, except maybe in 2020 and there only based on hindsight, not before but after seeing its price rise. Again, making it not that good a candidate for this strategy over its past. But that could change going forward...
Other issues, not related to your version, is the playing of the 3x leveraged ETFs. It should be noted that the starting dates for TMF, TYD was 4/15/2009 while TQQQ's starting date was 2/10/2010. There is nothing wrong with using 3x leveraged ETFs as long as we accept that those were the starting dates and that no transactions would have occurred prior to those dates. Using 3x long leveraged ETFs will tend to increase performance without having to pay leveraging fees. However, they are subject to return degradation if held for extended periods. The point would be to use TQQQ once you declare the trend as up (after 2/10/2010 evidently) and exit when the program made those switching to bond decisions.
If, and the if counts, if one wants to use those 3x leveraged ETFs, the starting date cannot be sooner than 2/10/2010 since prior dates will only put you in bond ETFs.
My take:
I raised the stakes to $1M. Used the 3x leveraged ETFs with no added leveraging. Shortened the wait days. Rescheduled the EveryDay() to 5 minutes after market open, and the WeekEnd() to 30 minutes before close. By rebalancing 120 minutes after the market opens on the WeekEnd(), you are missing almost one trade day per week. Nonetheless, TYD was not that good a choice over the period since at times its daily trading volume was quite low. The easy solution would be to simply remove it and only play TMF.
The added performance is mainly due to changing a few numbers in the program and going for the 3x leveraged ETFs. I consider the changes as something trying to maximize the time in the market, first by reducing the wait time on switching and then going for the early entry and the late rebalance on WeekEnd(). It did increase volatility, it did increase max drawdown, but also raised the bar in the profit department. Playing the $100k initial capital scenario should be rewarding as well for those interested. Just with these changes, the strategy had a remarkable 61.68% CAGR! Nonetheless, one can do even better as previously shown...
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.
Guy Fleury
For those wishing to push on the machine a bit, you might want to use some shorts when switching to bonds. The reasoning behind this is simple. You have something that declares the market as up or down. It has no middle ground. When up, you are in TQQQ, a 3x leveraged ETF. It should coincide with what, technically, you used to declare an upmarket. By using TQQQ, you increase the volatility and beta relative to a market average proxy (QQQ). It tends to help your returns if your upmarket declaration does coincide with an upswing in the overall market. A triple ETF can also produce more downside when your up declaration is wrong. So there is caution to be had. The importance of having a good 'bond' switcher.
The following chart shows when part of the bonds are replaced by a short. It has a 90.137% CAGR over the trading interval. Effectively showing that pushing on the 'out' side of the equation can also help to be even more productive.
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.
Vovik
Guy Fleury,
What is maximum and current drowdown of this strategy now in USD?
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.
Derek Melchin
Hi Radu,
The algorithm is stuck in TLT because everytime the extremeb condition is satisfied, the exit day is moved further into the future. We are still waiting for the condition
self.dcount >= self.outday + adjwaitdays
to be satisfied to signal the exit. See the plot of the backtest below for reference.
Here are some other issues with the algorithm:
-Since we are using Scheduled Events intraday, we need to subscribe to minute data resolution to avoid stale fills.
-Instead of calling AddEquity in rebalancewhenoutofthemarket and rebalance, we can move this to the Initialize method
-Replace
for symbol in self.Portfolio.Keys: if symbol.Value != "TLT": self.Liquidate(symbol.Value) self.SetHoldings("TLT", 1)
with
self.SetHoldings("TLT", 1, True)
I've resolved these in the backtest below. However, there is further work to do, including:
-Replace the return calculation in calcreturn with the MomentumPercent indicator.
-Replace the His→ry call in rebalance with the SimpleMovingAverage indicator.
-Replace the daily His→ry call in recordvars with a consolidator.
Hi Guy,
Yes, it is important to consider the start dates and liquidity of the securities we're trading. When implementing the revision I posted previously, the traded securities remained the same from a previous version of the algorithm. The algorithm was only changed to resolve the three issues mentioned in my previous post.
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.
Leandro Maia
Hi Derek!
May I ask you a question about the algo above? Why the stock symbols are not being added automatically by the universe selection and you need to use the line below:
self.SetHoldings(Symbol.Create(symbol, SecurityType.Equity, Market.USA), weight)
Regards,
Leandro
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.
Goldie Yalamanchi
Yes it seems the treasury bond yield curve signal (SHY) is triggering over and over again. Idk maybe we just remove the SHY signal altogether? Fed has printed like what $14T in QE and bonds, etc. I just don't think they can afford to have yield curve go up and afford to pay off those debts or the 20% of zombie companies surviving only because of 0% interest rate debt.
Anyways, here is the log with the signals and dates...
2020-10-06 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
2020-10-07 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
2020-10-08 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
2020-10-09 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
2020-10-12 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
2020-10-20 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
2020-10-21 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
2020-10-22 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
2020-10-23 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
2020-10-26 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
2020-11-03 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
2020-11-04 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
2020-11-06 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
2020-11-10 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
2020-11-11 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
2020-11-12 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
2020-11-13 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
2020-11-19 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
2020-12-02 11:30:00 : symbol XLI False DBB False IGE False SHY True UUP False G_S False U_I False C_A False
Nathan Swenson I don't know if adding a moving average (SMA, DMA, etc) as an "and" condition of sort would fix this problem. I have tried SMA type crosses and they are just too simplistic for market chop that routinely occurs where you wouldn't want to exit or enter.
I think we have to decide to fix the signal of SHY or not. But more often than not, SHY is the main signal that triggers the OUT condition, so if we remove it will the algo stop working? And I did one more basic test to remove it and the answer was 'yes'.
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.
Goldie Yalamanchi
Nathan Swenson after commenting out the bond yield (SHY) signal, it still performs very very well. And as of 4/24/2020 it enters and stays in the market.
Let me know thoughts. I think SHY and TLT will stay under pressure since the last 30 years they just want to destroy bonds and force all money into equities. Unless they will raise rates for inflation or something I think SHY will keep going lower and lower --- and generate that "fake" Fed created signal which doesnt underscore true equities weakness.
But anyways here is my backtest, commented out SHY bond signal. As aforementioned, as of 4/24/2020 it enters and stays in the market. 1844% return since 2008, not too shabby.
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.
Nathan Swenson
Thank you running those tests Goldie! Those are some decent results for SPY. The only issues I see are the increased drawdown and lower PSR score. I would be hesitant to remove the SHY signal. Yes it does improve the November results, but I do believe the SHY signal is of importance. Perhaps it's weighting needs adjustment in the Out decision? I will have to play around with the signals a bit. I still don't have a full understanding of the algo despite reading the code. I need to learn a bit more Python and work through some of the tutorial here at QuantConnect so that I can contribute more.
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.
Goldie Yalamanchi
So bonds SHY prices and TLT are inversely related. Since 2001 and especially since 2008, the treasury has been killing bond yields to pump up the economy right? Even since Reagan era there has been war on bond yields. So they can't keep pumping the economy if they raise bond rates. The US doesn't produce anything right? So how can they increase bond rates (SHY) and keep pumping equities? Speaking about SHY since the 2008 crisis it is not a good signal, because they will keep rates close to zero percent for a very very long time. Add to that they COVID measures to keep rates at zero for the next two years which the FED has very publicly declared. The algo prints out those true false signals based on 1% deviations in a number of signals like SHY or currency pairs, etc. Unless anybody believes bond yields will spike, SHY needs to be taken out of the formula. Just no longer a good indicator for American fiscal policy until we shift back to a more responsible Volcker era economics or at least until the FED normally raises rates again...because right now SHY yield is non existent. Using it, post Covid the algo may not fire properly for years.
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.
Raymond Simmons
Hi Guy,
I tried replacing the "out" bonds with leveraged short QQQ like SQQQ, but I am not seeing nearly the same results.
Is there anything else that I should change?
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.
Chak
Raymond, if you look at SQQQ, you'll find that the stock's value depreciates over time.
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.
Peter Guenther
Raymond Simmons: Thanks for joining the discussion and a valid observation! In line with your observation, when you go to the In & Out algo discussion (page 1) and the Intro (Ctrl + F search for "Intro") there, it notes "What we realized in our earlier discussions is that these alternative assets (bonds) critically contribute to the strategy’s overall return (‘riding the jitter wave’). However, we also found that the ‘out’ indicator is not sufficiently precise, i.e. it should not be used directly to go short on the market."
This is pretty much the gist of what you see in your backtest.
Dan Whitnable performed a similar test to yours on the original algo, going short on the SPY, and noted: "Here is the same algo as above but, instead of going 'out' of the market and into bonds, it goes short SPY using SH. Returns are not nearly the same, but moreover, volatility and drawdown are much higher. If the signals were finding when to get 'out' of the market, one would expect better performance? Just musing, but it almost seems the signals are really just finding when to get into bonds?" (see in the Quantopian discussion archive that Kyle K Oates has kindly shared in the In & Out discussion thread, page 1).
I reckon the quest of finding a set-up that creates a more precise 'out' signal that allows going short on the market is still an open endeavor.
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.
Chak
Raymond, to give a different response: When the in-out strategy decides it's better to exit the market it doesn't mean that the best solution is to short the market. When you short the market, it's because you're confident that it will drop a large amount very quickly, with or without influence by ETFs that represents as proxies for economic indicators.
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.
Aalap Sharma
Is there a diff betwwen calculating signal between
https://www.quantconnect.com/forum/discussion/9632/amazing-returns-superior-stock-selection-strategy-superior-in-amp-out-strategy/p1/comment-26829and the recent Guy's version.
I see the former has not switched to stocks yet.
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.
Aalap Sharma
nvmd. Figured the wait days are different. :(
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.
Peter Guenther
3 x leveraged SEL[“QQQ”] + I/O[“In & Out”] with disambiguated DEBT signal
The latest from the In & Out thread, yet, with in holdings TQQQ and out holdings TMF and TYD.
As usual, we should not bet the farm on it (<10-15% ?) since the future is likely to look different from the past ;) However, if it'll work to some extent it may create a decent boost in the portfolio.
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.
Rulak
Peter Guenther i changed paramater on v5 for wait days 5, which seems to generate 78,000% but drawdown did go up.
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.
Peter Guenther
Rojan Ulak: Oh wow, thanks for sharing! Indeed, there seems to be an advantage in being out of the market for shorter periods by default. The return flips ("# Determine waitdays empirically ...") seem to be quite effective in pulling up the waitdays exactly where they are required to be longer. Interesting! I think that Guy Fleury has shown elsewhere that reducing the default to only one waitday (self.INI_WAIT_DAYS = 1) produces the largest returns in the backtest (yet, for a different stock selection strategy but this finding might still also apply here; to be tested).
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.
Aalap Sharma
I may be a total noob on this but shouldnt wait days be some fuction of volatility or something ?
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.
Peter Guenther
Aalap Sharma: A bit different in this algo, see the lines where it says "# Determine waitdays empirically via safe haven excess returns, 50% decay". The wait days go up when the safe haven asset's return is positive (e.g., gold has a positive return) and the alternative asset goes from a positive to a negative return (e.g., silver's return flips).
Just one additional observation regarding Guy Fleury 's test: the post indicates a certain level of surprise that returns go up when changing the initial wait days from 0 to 1 (self.INI_WAIT_DAYS). It's a different algo but it includes the In & Out. When you change self.INI_WAIT_DAYS to 0 in the In & Out, it basically means that the algo is zero days out, i.e. you basically largely deactivate the In & Out logic.
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.
Aalap Sharma
Thanks for the pointer!
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.
Sudip sil
I am new to this platform. I have done some backtest and found that rebalance_when_out_of_the_market takes bit time to complete in compare of rebalance_when_in_the_market. As a result of that if out to in is trade required on friday, it does not happen on the same day, it takes a week to complete. So I am executing rebalance_when_in_the_market 5 minutes after the rebalance_when_out_of_the_market.
I am getting 24,513% which is slightly better than version 5.
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.
Rulak
Peter is there a reason you didn't add some type of stop trail loss to this strategy? Especially when playing with TQQQ drawdown goes very high in some of the backtesting.
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.
Peter Guenther
sudip sil: Thanks for sharing these results! I was wondering, are the performance difference really due to unfilled orders? Or are they because of a better/lucky timing in terms of when to sell off the out holdings and buy the in holdings (i.e. a slightly better price 5 minutes later). Did you have a chance to check the order book and found evidence for unfilled orders to rule out the alternative explanation (lucky timing)? Good luck with your further tests and keep us posted!
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.
Peter Guenther
Rojan Ulak: I would say it's definitely worthwhile to give this thought a go. Just musing about some challenges here: It will require a smart decision rule regarding whether and when we get back into the market after what kind of drawdown. Imagine the TQQQ pulls back 25% and we go out then and do not enter before the next algo cycle. What if the TQQQ quickly recovers the drawdown and we are standing on the side lines? We could say that we try to exit earlier, say at -10% and re-enter at -15%. But what if the TQQQ only falls by 14% and then quickly recovers? I reckon introducing a stop loss requires an entirely new layer of decision making/rules. Definitely worth a shot.
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.
Sudip sil
Peter Guenther Following is the result where my changes is not there. As per this 2020-04-02 out entry was done and 2020-05-01 Out was exited and In was done.
I have done some log.Please check followings. Algo sent a swap signal 2020-04-24, which is 1 week earlier. rebalance_when_in_the_market and rebalance_when_out_of_the_market were executed at the same time on friday, 2020-04-24. rebalance_when_in_the_market completed it's execution before rebalance_when_out_of_the_market. Since rebalance_when_out_of_the_market do not do Out to In swap, existing trades were not exited and new orders were not placed. It waited for a week to do the swaping.
Attaching the existing code with log(without my change).
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.
Peter Guenther
sudip sil: Nice investigative work there! The order overview, the logs, you got it all there, well done. Adding 5 minutes to the in rebalancing scheduling looks like a very good idea. Thanks for spotting this issue and recommending the change!
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.
Rulak
Attemtp with Stop trail loss, keep getting warning with message
Backtest Handled Error: Order Error: id: 39, Insufficient buying power to complete order (Value:-149500.3), Reason: Id: 39, Initial Margin:
but with 15% stop tailing loss on all invested postion, the algo does not seem to do very well relative to without stop trail loss
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.
Mateusz Pulka
Rojan Ulak
Did your algorithm cancel the opened stop-loss order (I did not check the code)? Cause this message about "Insufficient buying power" is about when you have a situation like this
1) Open trade buy QQQ and set stop loss
2) Aglo send out a signal so you close QQQ and buy the bond, however here at this moment you stop-loss order is still open.
3) In case when the price of QQQ reach the price of your stop order you will open short order on QQQ and your portfolio contains both positon QQQ short and bond long.
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.
Peter Guenther
Track: unleveraged strategies
Something I wanted to share with those who are after unleveraged strategies: A prior QC thread which was pretty popular developed the 'Momentum Strategy with Market Cap and EV/EBITDA'. The strategy was introduced by Jing Wu on 6 Feb 2018 (also see Vladimir’s and Goldie Yalamanchi’s discussion in the Quality Companies in an Uptrend thread). It comes down to combining a fundamentals factor (earnings) and momentum. As a short-hand, let’s refer to the selected firms as the ‘earnings rockets’.
SEL[Earnings Rockets] + I/O[In & Out, latest]
The stock selection part has a coarse filter (lines 125-134) to ensure that a firm’s (1) fundamentals data are available, (2) the stock price is not too small (>$5), and (3) it is among the 200 firms with the largest dollar volume (think: size and stock liquidity).
Then comes an additional filter (lines 137-156) that selects the top 200 firms with the best EV/EBITDA ratios.
Then comes a final filter (line 239-256) that calculates the selected firms’ stock returns over 70 days. The top 10 firms are selected (line 230). The strategy invests into these firms with an equal weight (line 235).
The selection (all three filters) is refreshed on a monthly basis.
The In & Out component is the latest version from the In & Out thread: In_out_flex_v5_disambiguate_v2
Total return: 4,101%
Sharpe: 1.69, Max drawdown: 18.70%, Comp. annual rate: 33.33%
PS: Due to the algo’s demands, the backtest takes quite a bit of time to complete. To gain a bit of efficiency, I was trying to save the self.History() call in the UniverseFundamentalsFilter by adding the stocks to the consolidator. However, I always ended up getting errors that stock symbols are missing and I assume that this is because the consolidator fires before the universe filters and adding symbols at the stage of the universe filters is too late and then the stocks’ prices are missing. Just speculating here.
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.
Leandro Maia
Peter,
thanks for sharing this latest algo. If you look further in Jing Wu's original thread you'll find an update where she removed the history call.
"We explore a new method to approximate the market capitalization. The formula is
market cap = Shares Outstanding * Price = Shares Outstanding * (Earnings Per Share * PE ratio)
In terms of fundamental variables in LEAN,
Instead of requesting the history close to calculate the Market cap, this method uses the fundamental data directly and could save the memory."
x.EarningReports.BasicAverageShares.ThreeMonths * (x.EarningReports.BasicEPS.TwelveMonths*x.ValuationRatios.PERatio) > 2e9
What I don't understand is why she didn't simply used:
(x.EarningReports.BasicAverageShares.ThreeMonths) * x.Price > 2e9
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.
Peter Guenther
Leandro Maia: Great call! The last line of code that you have shared is more direct and avoids the History() call in the Fundamentals Filter. Good stuff! I have attached the updated algo. The results are very similar to the first version which is good.
Total return: 4,017%
Sharpe: 1.68, Max drawdown: 18.70%, Comp. annual rate: 33.13%
There are only two direct History() calls left in the calc_return function (lines 239-40) that we may not be able to replace since the filtered stocks are unsubscribed (or subscribed too late) in the consolidator (?).
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.
Leandro Maia
Peter,
in the attached version I removed the history call from calc_return and added a standard ROC indicator added by OnSecuritiesChanged. This change didn't alter the performance, but I did two other that did:
1. Universe resolution change to minutes to avoid stalled prices. Small performance reduction
2. Universe selection performed every month start. In your orginal version universe is selected one day after rebalance but then is only and the next in signal is triggered which could mean months and the selection becomes to alleatory. This resulted however in some performance degradation.
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.
Thunder Chicken
Question. Is there a way to just limit the results to securities in NDX, SPX, etc. Basically to only trade the QQQ constituents?
Thank you!
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.
UK Bilgi Servisi
Just seems too good to be true. 50-60% annual compounding rate.. There should be something wrong here, either in the code or there is overfitting.
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.
Peter Guenther
Leandro Maia: This is pure coding magic, very nice work there! The changes all make a lot of sense, so this code should definitely be the basis for further work on the Earnings Rockets with In & Out. I reckon the only thing one could check is whether there is any benefit in performing a slower universe update (e.g. bi-monthly or every quarter). I mean, the backtest performance is impressive anyway.
Thunder Chicken: I know that there is a universe called QC-500 that mimics the S&P500 firms (documentation). I am not aware of a QQQ universe, but it might be something that may be coming at some point (?).
UK Bilgi Servisi: Overfitting may always be a concern with an algo that has more than say 3 or 4 parameters. Parameter sensitivity analyses can give an indication. For the 50-60% you refer to, these are algos trading 3 x leveraged ETFs. This is a furious bull ride and when the future does not play out like the past, leverage aggravates the problem. If the model is overfitted, and the kind of overfitting turns out to be a problem, then unleveraged trading is safer.
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.
Thunder Chicken
Peter Guenther - Sorry for an confusion. What I was saying, in respect to Earnings Rocket with In & Out, is there a way to limit the UniverseCoarseFilter(self, coarse) and only return stocks by sector (technology, healthcare, financials etc.,) or by which Index they are consitituents of, say just constituents which are part of the NASDAQ-100, S & P 500, or Russell 2000.
Thank you!
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.
Peter Guenther
Attached is a backtest for the Earnings Rockets with The Distilled Bear in & out algo. The total return is below the combo with the In & Out. However, there seems to be an issue of uninvested cash from Jul 2020 to now, looking like 7-10% of the total wealth are not invested which certainly drags on performance. It’s also interesting that the max drawdown (27.5%) is above the In & Out combo's (21.8%), since The Distilled Bear has a smaller drawdown when the SPY or QQQ are traded as the stock selection (compare in the In & Out thread). If you spot a coding-related explanation, give me a shout or post an update; I will also go through it again.
SEL[Earnings Rockets] + I/O[The Distilled Bear]
Total return: 2383%
Sharpe ratio: 1.35; Max drawdown: 27.5%; Compounding annual return: 28.0
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.
Peter Guenther
Thunder Chicken: What you could do is to use the Morningstar sectors, for instance by adding an appropriate condition to the CoarseFilter.
https://www.quantconnect.com/docs/data-library/fundamentalsFor the sectors, see here:
Ctrl + F for "Asset Classification". For instance, MorningstarSectorCode.Technology can give you the technology sector. For a more fine grained classification, you could drill down to the industry group level or industry level. The latter gives you specific industries such as Semiconductors, Solar, Biotechnology etc., so quite a detailed level for your selection.
Hope this helps / provides you with a starting point!
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.
Thunder Chicken
Peter Guenther - Thank you for sending this over. I am looking at it now.
-TC
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.
Simone Pantaleoni
Hi folks!
Here it is my contribution: adjusted CoarseSelection using weekly average volume based sorting (since I think the daily volume doesn't make any sense at all - :P )
16.1% drawdown - 4377% TR
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.
Peter Guenther
Nice work there, Simone Pantaleoni , thanks for sharing! I haven’t had a chance to have a detailed look; anyway, the algo looks very promising. Not sure whether you had a chance to check out Leandro Maia ’s point regarding the universe selection being performed one day after rebalance (= one day too late)? Irrespectively, I think that your algo gives the strategy a nice boost.
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.
Thunder Chicken
Peter Guenther - One thing that would be nice to see is the original Momentum Strategy with the distilled bear. I say such because the original momentum strategy rebalnced the stock portfolio on a monthly basis. The current version of earnings rockets doesn't seem to do so.
https://www.quantconnect.com/forum/discussion/3377/momentum-strategy-with-market-cap-and-ev-ebitda/p1 .
I've been working on it for a bit but can't seem to reconcile the logic.
Another way to say it would be, the SEL[Earnings Rockets] + I/O[The Distilled Bear] rebalancing monthly, when in market (i.e. owning stocks), but taking no rebalancing action when the I/O flag indicates bonds (i.e. owning TLT IEF etc)
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.
Damiano Bolzoni
Thunder Chicken I was working on the monthly rebalacing too....in 2020 the strategy doesn't buy any other stock after April and it sticks to the same ones forever...
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.
Leandro Maia
In the code I posted above, if you un-comment the lines below, you'll get a rebalance every 20 days, or you can change it to whatever number of days you like.
#if self.be_in and self.reb_count > 0 and (self.dcount - self.reb_count) == 20: # self.rebalance() # self.reb_count = self.dcountThe 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.
Thunder Chicken
Damiano Bolzoni - I am experiencing the same issue and attempting to identify the problem.
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.
Damiano Bolzoni
Thunder Chicken this is what is causing the issue:
# Only re-shuffle stock allocation when switching from out to in, not in-between
if not self.be_in_prior and self.be_in:
self.flip_flag = 1
self.rebalance()
self.flip_flag = 0
and
def UniverseCoarseFilter(self, coarse):
if (self.rebalance_flag or self.first_month_trade_flag) and (self.be_in or self.flip_flag):
(there is a similar check in the "UniverseFundamentalsFilter" function)
Because rebalance() sets the rebalance_flag back to 1, which in turns allows the filter functions to recalculate, no stock return is ever recalculated. On top of that, rebalance() is only called during the in-out switch...
I'm sure it si possible to clean up and "smil down" all these variables that are used to trigger the filter and the rebalance functions...but for now I just managed to trigger a refresh of the stocks after April 2020...I'm now testing the whole 2008-2020 period...
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.
Damiano Bolzoni
Sorry Leandro Maia I missed your early post(s). Thanks for fixing the rebalancing and for the clode cleanup :-)
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.
Goldie Yalamanchi
Yes I am sorry I think I may have introduced that self flip_flag code.
Also, there is another version here I have shared here that includes the Momentum + EV/Ebitda version to make sure to do at least one rebalance a month. I think Leandro Maia code does that when you uncomment those lines per my testing.
Additionally, the first ever trade is taking about a month (or in this case 20 days) to initially happen. I think some code has to be added in the beginning of the rebalance logic that if initially - Day 1 not in the market then get into the market! (as long as self.be_in or whatever flag is true or non-zero).
My rebalance when out of the market had this code in there, to initially make it trade and not wait as long as self.be_in was non-zero. I will just include the code snippet to not step on anyone's toes:
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.
Goldie Yalamanchi
def rebalance_when_out_of_the_market(self):
if self.be_in == 999:
self.flip_flag = 1
self.rebalance()
self.flip_flag = 0
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.
Thunder Chicken
Goldie Yalamanchi - What was the below regarding?
def rebalance_when_out_of_the_market(self):
if self.be_in == 999:
self.flip_flag = 1
self.rebalance()
self.flip_flag = 0
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.
Thunder Chicken
Peter Guenther - Just wondering if you figured out the leverage issue with SEL[Earnings Rockets] + I/O[The Distilled Bear]?
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!