Back to Community
Morningstar Industry Code?

Hello,
I know it's possible to pull the sector codes from the built-in Quantopian classifier but is it also possible to pull the industry code (similar, but more specific) too? If so, how? Or is this data premium?
Thanks,

7 responses

Bump.

Morningstar offers several classifiers which group securities:

morningstar_economy_sphere_code Sectors are consolidated into three major economic spheres or Super Sectors: Cyclical, Defensive and Sensitive. See appendix for mappings.

morningstar_industry_code Equities are mapped into one of 148 industries, the one which most accurately reflects the underlying business of that company. This mapping is based on publicly available information about each company and uses annual reports, Form 10-Ks and Morningstar Equity Analyst input as its primary source. Other secondary sources of information may include company web sites, sell-side research (if available) and trade publications. By and large, equities are mapped into the industries that best reflect each company’s largest source of revenue and income. If the company has more than three sources of revenue and income and there is no clear dominant revenue and income stream, the company is assigned to the Conglomerates industry. Based on Morningstar analyst research or other third party information, Morningstar may change industry assignments to more accurately reflect the changing businesses of companies.

morningstar_industry_group_code Industries are mapped into 69 industry groups based on their common operational characteristics. If a particular industry has unique operating characteristics—or simply lacks commonality with other industries—it would map into its own group. However, any industry group containing just one single industry does not necessarily imply that that industry is dominant or otherwise important. The assignment simply reflects the lack of a sufficient amount of shared traits among industries. See appendix for mappings.

morningstar_sector_code Industry groups are consolidated into 11 sectors. See appendix for mappings.

The definitions and mappings for these classifiers can be found in the Morningstar fundamental data appendix https://www.quantopian.com/help/fundamentals#industry-sector

These are all free and can be accessed in the 'asset_classification' group. See the data reference page https://www.quantopian.com/help/fundamentals#asset-classification. They are instantiated in either the research or IDE environment by simply using the 'latest' or 'Latest' methods ('Latest' can be faster if used in conjunction with a mask):

from quantopian.pipeline.data import morningstar as ms 

sphere = ms.asset_classification.morningstar_economy_sphere_code.latest  
industry_code = ms.asset_classification.morningstar_industry_code.latest  
industry_group = ms.asset_classification.morningstar_industry_group_code.latest  
sector = ms.asset_classification.morningstar_sector_code.latest

Sector is used quite often so there is a convenience method that can be used.

from quantopian.pipeline.classifiers.morningstar import Sector

sector =  Sector(mask=universe)

The sector codes can be found in the appendix (link is above). Here is a convenient list to cut and paste if needed.

MORNINGSTAR_SECTOR_CODES = {  
     -1: 'Misc',  
    101: 'Basic Materials',  
    102: 'Consumer Cyclical',  
    103: 'Financial Services',  
    104: 'Real Estate',  
    205: 'Consumer Defensive',  
    206: 'Healthcare',  
    207: 'Utilities',  
    308: 'Communication Services',  
    309: 'Energy',  
    310: 'Industrials',  
    311: 'Technology' ,  
}

Hi @Dan, is there such a list for industries too?

MORNINGSTAR_INDUSTRY_CODES = {  
  10101001: "Agricultural Inputs",  
  10102002: "Building Materials",  
  10103003: "Chemicals",  
  10103004: "Specialty Chemicals",  
  10104005: "Coal",  
  10105006: "Lumber & Wood Production",  
  10105007: "Paper & Paper Products",  
  10106008: "Aluminum",  
  10106009: "Copper",  
  10106010: "Gold",  
  10106011: "Industrial Metals & Minerals",  
  10106012: "Silver",  
  10107013: "Steel",  
  10208014: "Advertising Agencies",  
  10208015: "Marketing Services",  
  10209016: "Auto & Truck Dealerships",  
  10209017: "Auto Manufacturers",  
  10209018: "Auto Parts",  
  10209019: "Recreational Vehicles",  
  10209020: "Rubber & Plastics",  
  10210021: "Broadcasting - Radio",  
  10210022: "Broadcasting - TV",  
  10210023: "Media - Diversified",  
  10211024: "Residential Construction",  
  10211025: "Textile Manufacturing",  
  10212026: "Apparel Manufacturing",  
  10212027: "Footwear & Accessories",  
  10212028: "Home Furnishings & Fixtures",  
  10213029: "Packaging & Containers",  
  10214030: "Personal Services",  
  10215031: "Publishing",  
  10216032: "Restaurants",  
  10217033: "Apparel Stores",  
  10217034: "Department Stores",  
  10217035: "Home Improvement Stores",  
  10217036: "Luxury Goods",  
  10217037: "Specialty Retail",  
  10218038: "Gambling",  
  10218039: "Leisure",  
  10218040: "Lodging",  
  10218041: "Resorts & Casinos",  
  10319042: "Asset Management",  
  10320043: "Banks - Global",  
  10320044: "Banks - Regional - Africa",  
  10320045: "Banks - Regional - Asia",  
  10320046: "Banks - Regional - Australia",  
  10320047: "Banks - Regional - Canada",  
  10320048: "Banks - Regional - Europe",  
  10320049: "Banks - Regional - Latin America",  
  10320050: "Banks - Regional - US",  
  10320051: "Savings & Cooperative Banks",  
  10320052: "Specialty Finance",  
  10321053: "Capital Markets",  
  10321054: "Financial Exchanges",  
  10321055: "Insurance Brokers",  
  10322056: "Credit Services",  
  10323057: "Insurance - Diversified",  
  10324058: "Insurance - Life",  
  10325059: "Insurance - Property & Casualty",  
  10326060: "Insurance - Reinsurance",  
  10326061: "Insurance - Specialty",  
  10427062: "Real Estate - General",  
  10427063: "Real Estate Services",  
  10428064: "REIT - Diversified",  
  10428065: "REIT - Healthcare Facilities",  
  10428066: "REIT - Hotel & Motel",  
  10428067: "REIT - Industrial",  
  10428068: "REIT - Office",  
  10428069: "REIT - Residential",  
  10428070: "REIT - Retail",  
  20529071: "Beverages - Brewers",  
  20529072: "Beverages - Wineries & Distilleries",  
  20530073: "Beverages - Soft Drinks",  
  20531074: "Confectioners",  
  20531075: "Farm Products",  
  20531076: "Household & Personal Products",  
  20531077: "Packaged Foods",  
  20532078: "Education & Training Services",  
  20533079: "Discount Stores",  
  20533080: "Pharmaceutical Retailers",  
  20533081: "Food Distribution",  
  20533082: "Grocery Stores",  
  20534083: "Tobacco",  
  20635084: "Biotechnology",  
  20636085: "Drug Manufacturers - Major",  
  20636086: "Drug Manufacturers - Specialty & Generic",  
  20637087: "Health Care Plans",  
  20638088: "Long-Term Care Facilities",  
  20638089: "Medical Care",  
  20639090: "Medical Devices",  
  20640091: "Diagnostics & Research",  
  20641092: "Medical Distribution",  
  20642093: "Medical Instruments & Supplies",  
  20743094: "Utilities - Independent Power Producers",  
  20744095: "Utilities - Diversified",  
  20744096: "Utilities - Regulated Electric",  
  20744097: "Utilities - Regulated Gas",  
  20744098: "Utilities - Regulated Water",  
  30845099: "Pay TV",  
  30845100: "Telecom Services",  
  30946101: "Oil & Gas Drilling",  
  30947102: "Oil & Gas E&P",  
  30948103: "Oil & Gas Integrated",  
  30949104: "Oil & Gas Midstream",  
  30950105: "Oil & Gas Refining & Marketing",  
  30951106: "Oil & Gas Equipment & Services",  
  31052107: "Aerospace & Defense",  
  31053108: "Airlines",  
  31054109: "Business Services",  
  31055110: "Conglomerates",  
  31056111: "Rental & Leasing Services",  
  31056112: "Security & Protection Services",  
  31057113: "Staffing & Outsourcing Services",  
  31058114: "Engineering & Construction",  
  31058115: "Infrastructure Operations",  
  31059116: "Farm & Construction Equipment",  
  31060117: "Industrial Distribution",  
  31061118: "Business Equipment",  
  31061119: "Diversified Industrials",  
  31061120: "Metal Fabrication",  
  31061121: "Pollution & Treatment Controls",  
  31061122: "Tools & Accessories",  
  31062123: "Airports & Air Services",  
  31062124: "Integrated Shipping & Logistics",  
  31062125: "Railroads",  
  31062126: "Shipping & Ports",  
  31062127: "Trucking",  
  31063128: "Truck Manufacturing",  
  31064129: "Waste Management",  
  31165130: "Electronic Gaming & Multimedia",  
  31165131: "Health Information Services",  
  31165132: "Information Technology Services",  
  31165133: "Software - Application",  
  31165134: "Software - Infrastructure",  
  31166135: "Communication Equipment",  
  31167136: "Computer Distribution",  
  31167137: "Computer Systems",  
  31167138: "Consumer Electronics",  
  31167139: "Contract Manufacturers",  
  31167140: "Data Storage",  
  31167141: "Electronic Components",  
  31167142: "Electronics Distribution",  
  31167143: "Scientific & Technical Instruments",  
  31168144: "Internet Content & Information",  
  31169145: "Semiconductor Equipment & Materials",  
  31169146: "Semiconductor Memory",  
  31169147: "Semiconductors",  
  31169148: "Solar"  
}
MORNINGSTAR_INDUSTRY_GROUP_CODES = {  
  10101: "Agriculture",  
  10102: "Building Materials",  
  10103: "Chemicals",  
  10104: "Coal",  
  10105: "Forest Products",  
  10106: "Metals & Mining",  
  10107: "Steel",  
  10208: "Advertising & Marketing Services",  
  10209: "Autos",  
  10210: "Entertainment",  
  10211: "Homebuilding & Construction",  
  10212: "Manufacturing - Apparel & Furniture",  
  10213: "Packaging & Containers",  
  10214: "Personal Services",  
  10215: "Publishing",  
  10216: "Restaurants",  
  10217: "Retail - Apparel & Specialty",  
  10218: "Travel & Leisure",  
  10319: "Asset Management",  
  10320: "Banks",  
  10321: "Brokers & Exchanges",  
  10322: "Credit Services",  
  10323: "Insurance",  
  10324: "Insurance - Life",  
  10325: "Insurance - Property & Casualty",  
  10326: "Insurance - Specialty",  
  10427: "Real Estate Services",  
  10428: "REITs",  
  20529: "Beverages - Alcoholic",  
  20530: "Beverages - Non-Alcoholic",  
  20531: "Consumer Packaged Goods",  
  20532: "Education",  
  20533: "Retail - Defensive",  
  20534: "Tobacco Products",  
  20635: "Biotechnology",  
  20636: "Drug Manufacturers",  
  20637: "Health Care Plans",  
  20638: "Health Care Providers",  
  20639: "Medical Devices",  
  20640: "Medical Diagnostics & Research",  
  20641: "Medical Distribution",  
  20642: "Medical Instruments & Equipment",  
  20743: "Utilities - Independent Power Producers",  
  20744: "Utilities - Regulated",  
  30845: "Communication Services",  
  30946: "Oil & Gas - Drilling",  
  30947: "Oil & Gas - E&P",  
  30948: "Oil & Gas - Integrated",  
  30949: "Oil & Gas - Midstream",  
  30950: "Oil & Gas - Refining & Marketing",  
  30951: "Oil & Gas - Services",  
  31052: "Aerospace & Defense",  
  31053: "Airlines",  
  31054: "Business Services",  
  31055: "Conglomerates",  
  31056: "Consulting & Outsourcing",  
  31057: "Employment Services",  
  31058: "Engineering & Construction",  
  31059: "Farm & Construction Machinery",  
  31060: "Industrial Distribution",  
  31061: "Industrial Products",  
  31062: "Transportation & Logistics",  
  31063: "Truck Manufacturing",  
  31064: "Waste Management",  
  31165: "Application Software",  
  31166: "Communication Equipment",  
  31167: "Computer Hardware",  
  31168: "Online Media",  
  31169: "Semiconductors"  
}

I'm glad the Sector classifier exists but why did Quantopian stop at Sector and not include Industry?

I think it would be great to be able to do something like
company_pe.demean(groupby=Industry())
but there is no Industry classifier and I admit I'm novice python coder and I don't know how else to achieve this.

Maybe other people have achieved this but I haven't found anything in the forums which is surprising because it's such a well known/used valuation.

Would something like this work? It compares the individual stock's avg EPS over 252 days to their respective Industry Code.

 class Industry(CustomFactor):  
        inputs = [factset.Fundamentals.eps_basic_gr_qf, Fundamentals.morningstar_industry_code]  
        window_length = 252  
        def compute(self, today, assets, out, pe, industry_codes):  
            df = pd.DataFrame(index=assets, data={"pe_ratio": pe[-1], "industry_codes": industry_codes[-1]})  
            out[:] = df.groupby("industry_codes").transform(np.mean).values.flatten()