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.
Johannes Mauritzson
oh, scratch my last post that as well then :)
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.
Thushara Silva
Yes, its working again. Thank you. Trying it live right now.
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.
Warren Harding
I don't recommend trading it live with cash as is. It doesn't seem to make any money if the fees are too high, I have a version with fees modeled and checked. It needs to have the market orders converted to limit orders on GDAX or be ported to a platform with low fees like Binance in order to be profitable.
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.
Warren Harding
Here's the same algo with fee modelling. I set the fee to the same value as GDAX's 'taker' fee. As you can see it does not profit. It needs to be modified to take advantage of GDAX's free for 'makers' fee structure. I'm working on that but probably won't give away the results for free, sorry.
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.
Samuel Cutler
Hey Warren, I'm running an algo on GDAX live trading, im fairly new to coding. I'm having a problem with my code i belive. Wondering if you had some insight for me. What it does is buys btcusd then sells then sometimes its able to buy litecoin or ether and then sell but always after the first or second trade, it comes up invalid in the orders and the algo stops trading? Any info would help, Thanks!
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.
Samuel Cutler
Hey warren I played with your algo as well look what happens when you set emaofchangelenght 1 and 2 to 5 and back test from Feb 2018 to March, huge returns, I'm also very new to this so I do not know if that changes anything else 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.
Warren Harding
Hi Samuel. I think Quantconnect might use asynchronous calls when live trading so that could be the problem. You might have to put a Thread.Sleep in to delay things so that the funds from a sale will be ready to make the next purchase. Ya, I noticed that if you shorten the trade frequency the returns go up, but you get a more volatile 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.
Warren Harding
Hi Samuel. I tried out your suggestion, the equity curve actually looks pretty smooth. Interesting, thanks.
Compounding Annual Return: 6443733821369940000000000%. Hope it's not all too good to be true.
Here's Samuel's suggestion with fee modelling. Still no slippage, but slippage is pretty low on GDAX for these instruments so it might actually profit.
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.
Samuel Cutler
Hey Warren thanks for the help, i think that would be the problem, would you be willing to show me exatly how to do that? again im fairly new to coding, I have been day trading for 10 years now and im trying to learn how to set up some algos to run my strageties. I find it very interesting just very difficult for me! Thanks again
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.
Warren Harding
Note that slippage is only going to be low if you are running a small account and buying at the bid/ask. If you are running a larger account you will need position building code and will have to consider slippage more carefully.
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.
Warren Harding
Hi Samuel. Sure, just Google Thread.Sleep to see how the call works. You might need to add a using statement. Then insert the Thread.Sleep call in between the sale and the purchase to create the delay. I typically bill people for assistance more complex than that, sorry.
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.
Nate Betz
Hi! Just a couple of comments from the peanut gallery.
First, thanks Warren, for sharing your algorithm!
Second, I just want to suggest that I think QC is modelling extremely optimistic trade executions. Towards the latter part of the backtest period, the algo is doing $1M trades, and filling them at market price. Based upon my current experiences live trading on GDAX, I'm not sure those kinds of fills are realistic for the liquidity of these crypto markets. And it's the compounding size of these trades that is leading to most of the returns in the backtest.
Lastly, I'm perhaps missing something, but it appears the emaOfChanges2Indicator is not actually being used, since the weight is set to 0. I just mention it in case anyone is looking to refactor/simplify. I removed it from the algo and got the same backtest results.
Cheers and happy trading.
Nate
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.
Jared Broad
We don't recommend putting Thread.Sleep into your code -- this will guarentee your algorithm explodes from RAM issues as sleeping will cause the tick data stream to back up.
Samuel Cutler "it comes up invalid in the orders and the algo stops trading" - this is because you've likely spent the cash in your account and don't have the coins to trade. Please see the FAQs and pay close attention to the error messages -- we've made them pretty descriptive now.
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.
Warren Harding
Hi Nate,
Yes, the optimistic trade executions you speak of are the same thing as I mentioned above with slippage and larger accounts.
Yes, you could remove the emaOfChanges2Indicator but you would be defeating what 'The Scaffolding' does. It allows you to quickly model strategies based upon trend and curvature. You've removed the ability to quickly check and see if curvature of the price graph affects returns. I left it in there so people could check curvature based strategies, even though it is not used in this case. I describe 'The Scaffolding' in further detail above.
Thanks, Warren
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.
Warren Harding
Two things. One are asynchronous calls likely to cause problems when trading this algo live? In particular, will the Liquidate call still be processing when the call to SetHoldings is made, resulting in a lack of funds error? If so what is the best way to wait for the Liquidate call to go through?
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.
Jared Broad
Liquidate is synchronous up to 5s -- if the market order takes longer than 5 sec to fill it'll move to the next line of code.
If there are multiple orders in flight weird things can happen! We're limited by how fast the exchanges can fill. You can increase this timeout by setting the market order timeout variable here:
C#: Transactions.MarketOrderFillTimeout = TimeSpan.FromSeconds(30); Py: self.Transactions.MarketOrderFillTimeout = TimeSpan.FromSeconds(30)
PS: Warren; I've edited your comment ("the framework") to the scaffolding to prevent confusion with the official QuantConnect Algorithm Framework we're shipping this week.
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.
Warren Harding
Thanks Jared!
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.
Nate Betz
Sorry Warren, I zero'd in on the code and must have missed your full description of 'The Scaffolding'.
Just for fun, here's another implementation of your Scaffolding as a custom indicator. There's also a RateOfChangePercent indicator that we can do an EMA of, but it seems to give slightly different calculations.
namespace QuantConnect {
public class RocEmaIndicator : WindowIndicator<IndicatorDataPoint>
{
public ExponentialMovingAverage EMA1 { get; private set; }
public ExponentialMovingAverage EMA2 { get; private set; }
//public RateOfChangePercent ROC1 { get; private set; }
public RollingWindow<decimal> RW1 { get; set; }
public RollingWindow<decimal> RW2 { get; set; }
public decimal changes1Ratio = -1.0m; //The influence of change upon fitness.
public decimal changes2Ratio = 0;
public RocEmaIndicator(int emaPeriod, int historyPeriod)
: this(String.Format($"ROCEMA{emaPeriod}_{historyPeriod}"), emaPeriod, historyPeriod)
{
}
public RocEmaIndicator(string name, int emaPeriod, int historyPeriod)
: base(name, historyPeriod)
{
//ROC1 = new RateOfChangePercent(name + "_ROC1", historyPeriod);
EMA1 = new ExponentialMovingAverage(name + "_EMA1", emaPeriod);
EMA2 = new ExponentialMovingAverage(name + "_EMA2", emaPeriod);
RW1 = new RollingWindow<decimal>(historyPeriod);
RW2 = new RollingWindow<decimal>(historyPeriod);
}
public override bool IsReady
{
get { return EMA1.IsReady; }
}
protected override decimal ComputeNextValue(IReadOnlyWindow<IndicatorDataPoint> window, IndicatorDataPoint input)
{
//ROC1.Update(input);
RW1.Add(input.Value);
RW2.Add((RW1.First() - RW1.Last()) / RW1.First());
if (RW2.Count() > 1) EMA1.Update(input.Time, RW2.First());
if (RW2.Count() > 1) EMA2.Update(input.Time, RW2.First()-RW2.Last());
return changes1Ratio * EMA1;
}
public override void Reset()
{
RW1.Reset();
RW2.Reset();
EMA1.Reset();
EMA2.Reset();
base.Reset();
}
}
}
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.
Warren Harding
Thanks Nate! Your code looks a bit more concise than mine, nice.
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.
John Schwartz
Say I added USD while my algo was running Live. I want the algo to see the money and start using it. Right now after load it doesn't see my money. Is there a way to just re-initialize that object without down stream effects?
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!