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).
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
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
 Â
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?
Â
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."
Â
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)
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 ---
Derek Melchin
Hi Spacetime,
This error is because we are calling the `.index.levels` 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.
Goldie Yalamanchi
Vladimir thank you so much for this cleanup! Yes it looks much better than what I had.
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?
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.
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.
Anthony FJ Garner
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!