We're proud to announce that we now support Morningstar Sector, Industry Group, and Industry codes! Sector, Industry Group, and Industry codes sort stocks based on their general market classification, with Sector being the coarsest classification (i.e, Energy) and Industry the finest-grained classification (i.e., Oil and Gas Drilling, Oil and Gas Midstream, etc.). This classification information is part of the Fundamental Data library and can be accessed like any other Fundamental Data in an algorithm.
To demonstrate these new features, we've created a Universe Selection module that returns exclusively Symbols in the banking industry. The Coarse Selection does our initial filtering for stocks with Fundamental Data and positive volume and price. The Morningstar industry filtering is done in the Fine Selection function using MorningstarIndustryGroupCode.Banks (which is equivalent to 10320, and the full list of codes can be found here). Our final list of Symbols will be banking stocks with positive trading volume and price, sorted in descending order of liquidity.
Morningstar Industry/Sector codes and other asset classification helpers are available as part of our Fundamental Data Library, and you can view the code for this and check out the other features on GitHub here. We've attached a backtest that gives a simple demonstration of how you can incorporate our new Fundamental Data features into your code and use our new Universe Selection module -- Banking Stocks!
def SelectCoarse(self, algorithm, coarse):
'''
Performs a coarse selection:
-The stock must have fundamental data
-The stock must have positive previous-day close price
-The stock must have positive volume on the previous trading day
'''
if algorithm.Time.month == self.lastMonth:
return self.symbols
filtered = [x for x in coarse if x.HasFundamentalData and x.Volume > 0 and x.Price > 0]
sortedByDollarVolume = sorted(filtered, key = lambda x: x.DollarVolume, reverse=True)[:self.numberOfSymbolsCoarse]
self.symbols.clear()
self.dollarVolumeBySymbol.clear()
for x in sortedByDollarVolume:
self.symbols.append(x.Symbol)
self.dollarVolumeBySymbol[x.Symbol] = x.DollarVolume
return self.symbols
def SelectFine(self, algorithm, fine):
## Performs a fine selection for companies in the Morningstar Banking Sector
if algorithm.Time.month == self.lastMonth:
return self.symbols
self.lastMonth = algorithm.Time.month
# Filter for banking stocks using MorningstarIndustryGroupCode.Banks (equivalently, this is 10320)
filteredFine = [x for x in fine if x.AssetClassification.MorningstarIndustryGroupCode == MorningstarIndustryGroupCode.Banks]
sortedByDollarVolume = []
# Sort stocks on dollar volume
sortedByDollarVolume = sorted(filteredFine, key = lambda x: self.dollarVolumeBySymbol[x.Symbol], reverse=True)
self.symbols = [x.Symbol for x in sortedByDollarVolume[:self.numberOfSymbolsFine]]
return self.symbols
SLPAdvisory
Extremely grateful for this!
Michael Manus
very useful
Valery T
Stevin Chac
HanByul P
Jimmy Hendricks
Elliot Parker
Huy Hoang
Michael Manus
Dear QC - Team put this example please in the tutorials and and post a link to the tutorials somewhere. in the community forum is a link to the github examples so maybe.........
this post is maybe very very important for others and should be highlighted. on the right side in the forum below the github examples links is some space for prominent/vip code examples.
this post will disappear in a few weaks and no one will ever find it, except if you pin it somewhere
:)
Jared Broad
Mike HU
It woudl be helpful that minimal examples were avaialble in all supported languages (just like on MS sites you can click C# or C++). Otherwise it's not even clear if that's spcific to python only
Link Liang
Hi Mike,
Here is our documentation regarding Morningstar Asset Classification. Both C# and Python example code snippet are there. I have also converted the example from JayJay to C# in this backtest, hope it would help you get started with this exciting feature!
Aleksandr Nalivajko
Thx for that.
Can I make SelectCourse return not only a list of symbols, but also IndustryGroupCode of those symbols?
Alethea Lin
Hi Aleksandr,
Fundamental data is selected and accessed via fine fundamental universe selection, so you can return the IndustryGroupCode along with the symbols in the fine selection step. To get the industry code, you will use “.AssetClassification.MorningstarIndustryGroupCode” command.
Check out “Data Library – Fundamentals” to learn more about using fundamental data!
Hope this helps and thanks for your support!
E Katir
Thank you, Jared and QC Team, This is a a great milestone!
JayJayD
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!