Herwith a version of the long, long thread which presented "Quality Companies in an Uptrend" on the Quantopian forum.
Quality Companies in an Uptrend
This version promised vast profit on Quantopian data and code. Needless to say translated to different code and data here on Quantconnect, the results differed. I used it to singe out companies which had taken on high levels of debt. Which provides non -recourse leverage to the investor when markets are going well. Or can do. It is the sort of technique used in private equity levereged buy outs. Not so great when the market crashes and it becomes difficult to service the debt.
Derek Melchin
Hi Anthony,
Thanks for sharing this with the community!
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
Anthony FJ Garner: Very nice work converting this algo over to the QC platform! I know that many of the 'old Quantopians' were waiting for this moment, since the algo was extremely popular and extensively used and discussed :) Kudos!!
What could be interesting: On Quantopian, we found that some return improvements are possible by combining this stock selection strategy with an in & out type strategy (timing the market). The "Quality Companies in an Uptrend" algo also has a market timing strategy built in (death cross type; crossing of MAs). Yet, this market timing has weaknesses. We found that this stock selection strategy works particularly well with Vladimir's in & out algo (ROC).
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.
Anthony FJ Garner
Thanks Peter, for the comments. The work had been done many months ago, so I thought I may as well publish it since I have abandoned the strategy. At least as regards using "high debt" companies. The huge apparent profits on Quantoipian back testing evaporated here on Quantconnect. I was also increasingly worried that the parameters had simply been fitted to the data. By me of course. In my near 20 years of fooling around with this stuff all I have really learned is that one is mostly fooling onself with a strategy such as this; at least using the parameters and fundamental factor I chose.
I have to admit, I have never really found anything of any great worth in all these years. Other than simple asset allocation strategies. I hope you guys fare better.
A
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.
Jonathon Tzu
Hi, I've been doing some backtesting of strategies from Quantopian on QC, and while I agree there is a notable decrease in performance by a few percent a year, the returns are largely the same (I think over 20 years, QC has about half the returns, but this might very well be because leverage wasn't as well controlled on Quantopian). I've attached a version based on a strategy I was running on Quantopian that appears to perform about as well as it did there. There are several further corrections that can be made on this strategy to vastly increase returns. In truth, I've found that the factors that performed best in Quantopian do outperform on QC as well. Any performance differences are likely in large part due to the differences in how the two platforms represent data. This was based on the idea that following market corrections, you should invest in stocks that have the lowest momentum (effectively a high beta/quality strategy that uses market timing to predict which cycle the market is at). Testing this versus the original model and a pure highest momentum strategy, this did much better.
I think with some modifications, this strategy can be made to match Quantopian results. I'm also trying to reimplement the Canslim distribution days strategy that did quite well. The original strategy was copied from:
https://www.quantopian.com/posts/long-short-portfolio#5f8b62dfa77d39000c522c0e
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). It would be very interesting if you could remake that on QC.
This strategy was modified from:
https://www.quantconnect.com/forum/discussion/3377/momentum-strategy-with-market-cap-and-ev-ebitda
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.
Anthony FJ Garner
Jonathon Tzu
Nice returns, nice code.
What I have come to dislike about long term systems is that when you start to trade one, it is like setting out on an ocean in a supertanker. Everything is in slow motion and measured over a number of years. When do you decide it works or when do you decide it was a system designed around past data?
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.
Anthony FJ Garner
Incidentally anyone using the long bond as a safe haven should look at 1980 30 year bond yields. The period when Paul Volcker was in office. Bond yields rose rapidly for 6 months and the 30 year bond declined by almost 50%. Stocks and bonds do not always set each other off.
Another facet of back testing. And looking at short time spans.
As per the Washington Post obituary:
"Mr. Volcker’s greatest historical mark was in eight years as Fed chairman. When he took the reins of the central bank, the nation was mired in a decade-long period of rapidly rising prices and weak economic growth. Mr. Volcker, overcoming the objections of many of his colleagues, raised interest rates to an unprecedented 20 percent, drastically reducing the supply of money and credit.
At a shocking, unscheduled Saturday night news conference announcing those steps just two months after taking office, in October 1979, Mr. Volcker was coy about the likely economic impact."
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.
Jonathon Tzu
I think that no modern day Fed chair would be quite so rash as to increase yields that rapidly. However, I've found that using the 200/50 day MAs and using market timing via the Canslim Distribution days and the In and Out strategy from quantopian predicts bond returns quite well. (this captures about 50% of all upward trends but almost none of the downside from bonds falling). Effectively it tiers market conditiosn into three zones and says if the trend is generally up, then go long into bonds with increasing leverage depending on your confidence. I was wondering how to set this up in futures on QC.
pricex=data.history(context.bonds,"close", 253, "1d")
pricemin=min(data.history(context.bonds,"low", 30, "1d"))
pricemax=max(data.history(context.bonds,"close", 30, "1d"))
pricenow=max(data.history(context.bonds,"high", 1, "1d"))
change=pricex.pct_change(126).iloc[-1]
change2=pricex.pct_change(30).iloc[-1]
change=(data.history(context.bonds,"low", 69, "1d")).mean()
cost=context.portfolio.positions[context.bonds].cost_basis
curr=context.portfolio.positions[context.bonds].last_sale_price
if (context.TF_filter3==False or context.TF_filter2==False)and (context.switches==0 or today<.92*spymax) and pricenow>.98*pricemax:
order_target_percent(context.bonds, 4)
elif change>0 and change2>0 and pricenow>.98*pricemax and context.TF_filter3==False:
order_target_percent(context.bonds,1)
elif context.TF_filter3==True and context.TF_filter2==True and today>.98*spymax and today>1.08*spymin and change<-.02 and change2<0 and context.switches==0 and cost<1.04*pricemin:
order_target_percent(context.bonds,-.5)
else:
order_target_percent(context.bonds,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.
Spacetime
Jonathon Tzu
fyi- I was testing this strategy and receiving the following error as shown below.
It is occuring on Jul 2, 2007 during backtesting.
I will share the solution if I solve it.
Error Message:Runtime Error: In Scheduled Event 'SPY: MonthStart: 10', AttributeError : 'Index' object has no attribute 'levels' AttributeError : 'Index' object has no attribute 'levels'Stacktrace:QuantConnect.Scheduling.ScheduledEventException: In Scheduled Event 'SPY: MonthStart: 10', ---> System.Exception: AttributeError : 'Index' object has no attribute 'levels' ---> Python.Runtime.PythonException: AttributeError : 'Index' object has no attribute 'levels' at Python.Runtime.PyObject.Invoke (Python.Runtime.PyObject[] args) [0x00035] in <c56ab175820d412caf052e079c2ab9ef>:0 at QuantConnect.Scheduling.ScheduleManager+<>c__DisplayClass15_0.<On>b__0 (System.String name, System.DateTime time) [0x00011] in <76bf9fe7f75d4895a52327a40a07b107>:0 at QuantConnect.Scheduling.ScheduledEvent.OnEventFired (System.DateTime triggerTime) [0x00027] in <76bf9fe7f75d4895a52327a40a07b107>:0 --- End of inner exception stack trace --- --- End of inner exception stack trace ---
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 Spacetime,
This error is because we are calling the .∈dex.≤vels property on an empty DataFrame.
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.
Vladimir
Anthony FJ Garner
I found in this thread a Goldie Yalamanchi strategy that is closer to Chris Cain's
original definition of quality and the latest posts in Quantopian's "Quality Companies in Uptrend".
It has some leverage control problems.
Let's help him to polish 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.
Goldie Yalamanchi
Vladimir thank you so much for this cleanup! Yes it looks much better than what I had.
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
Derek,
Some time ago, I was working on a strategy like the one you posted here, and there was
a leverage problem.
So, I took your version, made some changes just to plot real account leverage and target leverage.
And here's what I got:
Derek Melchin original LEV = 1
Derek Melchin original LEV = 1.2
Where did these bursts of leverage came from?
What would you advise how to avoid them?
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 Vladimir,
The fluctuations in leverage occur because the value of the portfolio is changing between rebalances. See the attached backtest plot for reference. A remedy for this is to rebalance more frequently.
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.
.ekz. INVESTOR
Hi Jonathon Tzu
Were you able to make any progress reimplementing the Canslim distribution days strategy?
I'm interested to see how this was done, and unfortunately the original Quantopian code doesn't exist anymore.
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.
HanByul P
Hi Jing Wu, Just a quick question: Why is this algo waiting for a month and starting to run from a second month? Is it for warming up? Can we modify this algorithm to run from the first month? Just remove the flags? Please let me know. 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.
Weiheng Liang
Thank Jing.
market cap = Shares Outstanding * Price = Shares Outstanding * (Earnings Per Share * PE ratio)
That's what I was waiting for. It's a huge improvement for my 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.
Xi Liu
Hi Jing Wu,
1. I ran the Algo, and found the exit function(when current SPY price is lower than last N-day moving average price, then liquidate all the open positions and buy TLT.) doesn't work all the time. The exit function doesn't work, making it performs bad on crisis.
The momentum strategy has relatively higher volitility. I think one of the drawback of momentum strategy is failing to act quickly to close a bad position. I'm considering to add a Stop Market Order of the portfolio composite seperately. However, I'm new to do an alogo with python, after reading the Documentation and browing the internet, I only learned how to add StopMarket order while making market order, like this:
self.MarketOrder(self.baba, 300)
self._stopMarketTicket = self.StopMarketOrder(self.baba, -300, slice['BABA'].Close * Decimal(0.95), "stop market")
This algo's code seems complex to me, I can't find the place to get the price and deploy the StopMarket order.
Can you give me some instructions on this problem?
2. I want to test the algo with leverage, for example, 1.5 leverage then I modify LINE 96:
weight = 0.99/len(chosen_df)
for symbol in chosen_df.index:
self.AddEquity(symbol)
self.SetHoldings(symbol, weight)
I change 0.99 to 1.5, but it doesn't work. Do you know how to set the weight here?
Thank you a lot.
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.
Jon Quant
I have sprinkled a bunch of debug lines in the code just to analyze the behavior and I have noticed that if I set the following dates:
SetStartDate(2004, 1, 1); SetEndDate(2004, 4, 1);
...the value for the "symbols" variable in "FineSelectionFunction" gets assigned on 01/03/2004 only to be used by the "rebalance" function a month later, 02/02/2004. This tells me that the rebalance is operating on a fine "symbols" list that is a month old. Is this intentional?
One other behavior that I have noticed is that the "CoarseSelectionFunction" and "FineSelectionFunction" never gets called on the "MonthStart" day. In my example date window, it never gets called on 01/02/2004. Is the "MonthStart" schedule somehow interfering with the Coarse and Fine events?
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.
Jing Wu
Hi Xi Liu,
You can use self.StopMarketOrder() everywhere in your algortihm. For the stop price, you can use
"self.Securities["BABA"].Close" * Decimal(0.95) instead of "slice['BABA'].Close * Decimal(0.95)" because you can only get the slice data in OnData() method.
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.
HanByul P
Hi Jing Wu, I cloned your new method (for Market Cap) algo and ran for 2015 to March 1st of 2018. I found that the leverage went up to 500% (5x) in the early 2016 and came down to 300% (3x) in the end of this backtest period. You set the maximum weight to 0.99x as below. I guess something should be fixed. Can you take a look and fix the leverage control (e.g. maximum 2.0x)? Thank you.
weight = 0.99/len(chosen_df)
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.
Ton86
Hi Jing Wu,
I ran this today 4/2/2018 and was looking for the trade signals to occur by 10am PST since that seems to be the time the trades occur in the backtesting. Do we need to wait until end of first day of the month or should the signals be there by 10am PST, or another time?
When setting this up for trading live what types of alterations might need to be made? Is there a page/link that describes this or is this something support helps with after creating a live account?
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.
Ton86
Jing Wu,
Also seeing errors like this:
Backtest Handled Error: The order quantity for TLT cannot be calculated: the price of the security is zero.
Doesn't look like April 2018 TLT trade is getting executed because of it. Could it be that the algo is looking at the first of the month for the price but isn't seeing it because the first falls on a weekend?
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.
Yulong Jiang
Hi, Jing, I am new to QuantConnect so a little confused on your code.
it seems that you do everything on Intialize() and pass on OnData(), does it mean Initialize() will run many times instead of just setting the initialial condition?
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.
Michael Manus
nope only once
everything?? settings holdings are in rebalance ....
check the bootcamp(-tab) in the algorithm lab
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.
Wei Chian Ong
I'm a little bit confused by the code snippet below. We check the moving average exit gate, and if it shuts, we loop through each position, if it's not TLT (bonds), then we exit the position. That makes sense.
if self.Securities[self.spy].Price < spy_hist.mean(): for symbol in self.Portfolio.Keys: if symbol.Value != "TLT": self.Liquidate()
But, when we use self.Liquidate() and don't specify a security, doesn't it just liquidate every single position in the portfolio? Why bother to loop through the Portfolio keys at all, if we are just going to liquidate everything anyway? In my head it seems that self.Liquidate(symbol) or self.Liquidate(symbol.Value) would make more sense. Can someone tell me what I am missing?
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.
Weiheng Liang
Wei Chian Ong, what the code Liquidate() will do is possibly more tricky than you imagined. I suggest you check the code inside ideally debug carefully by using VS.
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.
Wei Chian Ong
Thanks for the reply. I've had a look at your previous post regarding the self.Liquidate() method, and my question probably doesn't run as deep as the intricacies of dark pools and slippage in actual trading. It's more of a question regarding the coding itself. The documentation and this forum post and reply seem to indicate that using self.Liquidate() without a security specified, will liquidate all positions, and I was having trouble understanding why we bother looping through each symbol in the portfolio and checking if it's not treasury bond ETF, if we go ahead and liquidate everything anyway, would it not make more sense to use self.Liquidate() with the actual position we are currently looping 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.
Weiheng Liang
I was not meaning dark pools. I was just saying we should look inside the detail codes of Liquidate() in VS if there is something confused.
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.
Wei Chian Ong
I'm not familiar with how to use visual studio (I assume that's what VS stands for), so I'll have to try it using log or debug calls.
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.
Nick Jensen
I cloned this algorithm and received an error "Invalid Token" on the self.SetStartDate function, so am unable to run or backtest. Is anyone receiving this same error? Is there an easy fix?
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.
Wei Chian Ong
I think I kept getting the same Nick and I wasn't sure why either. I deleted the code for the self.SetStartDate and self.SetEndDate and then re-typed them manually in case it was a whitespace issue or something (probably a very inefficient way to do that anyway). Same problem, but I repeated that several times and eventually it worked. Not a very scientific response to your question .......
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
The invalid token is from python 2.7 to python 3.6 upgrade. Since python 3.6 numbers can't be prefixed with 0 -- e.g. "01"
If you cloned an old backtest it can have dates with 2001, 01, 01 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.
Leng Dieb
I am trying the codes for the test on paper live server but it does not seem to generate any trade. Could you please advise anything need to be changed to run live for the paper trading?
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.
Tocht
Any updates?
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!