Notebook
In [3]:
from quantopian.pipeline.data import Fundamentals
from quantopian.pipeline.data import morningstar
from quantopian.pipeline.data import morningstar as ms
from quantopian.pipeline.factors import AverageDollarVolume
from quantopian.pipeline.factors.morningstar import MarketCap
from quantopian.pipeline.classifiers.morningstar import Sector, SuperSector
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline import Pipeline
from quantopian.research import run_pipeline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from pandas import DataFrame as df
import time
from quantopian.pipeline.filters import QTradableStocksUS

def make_pipeline():
    market_cap = Fundamentals.market_cap.latest
    price = USEquityPricing.close.latest
    volume = USEquityPricing.volume.latest
    sector = Sector()
    super_sector = SuperSector()
    industry_group = ms.asset_classification.morningstar_industry_group_code.latest
    industry_code = ms.asset_classification.morningstar_industry_code.latest
    return Pipeline(
        columns={
            'MarketCap': market_cap,
            'Price': price,
            'Volume': volume,
            'Super Sector Code': super_sector,
        #   'Sector Name', 
            'Sector Code': sector,
            'Industry Group Code': industry_group,
            'Industry Code': industry_code
        },
        screen=QTradableStocksUS()
    )

my_pipe = make_pipeline()
In [4]:
result10 = run_pipeline(my_pipe, '2018-03-20', '2018-03-20')
In [5]:
test = local_csv('Industry_classification.csv')

pd.merge(result10, test, on=['Industry Code', 'Super Sector Code', 'Sector Code', 'Industry Group Code'])
 

#2300 Columns & 13 Columns

#print(result10.shape)
    ##2152 stocks, 7 columns
#print(test.shape)
    ##148 Industry Codes & 8 Columns
Out[5]:
Industry Code Industry Group Code MarketCap Price Sector Code Super Sector Code Volume Super Sector Name Sector Name Industry Group Industry Name
0 31061119 31061 1.160102e+10 24.040 310 3 2072085.0 Sensitive Industrials Industrial Products Diversified Industrials
1 31061119 31061 1.801403e+10 77.885 310 3 472849.0 Sensitive Industrials Industrial Products Diversified Industrials
2 31061119 31061 1.404176e+09 23.375 310 3 376105.0 Sensitive Industrials Industrial Products Diversified Industrials
3 31061119 31061 1.144894e+09 44.100 310 3 95425.0 Sensitive Industrials Industrial Products Diversified Industrials
4 31061119 31061 3.307453e+09 62.110 310 3 113134.0 Sensitive Industrials Industrial Products Diversified Industrials
5 31061119 31061 9.517834e+08 22.180 310 3 118342.0 Sensitive Industrials Industrial Products Diversified Industrials
6 31061119 31061 5.653824e+09 94.490 310 3 77321.0 Sensitive Industrials Industrial Products Diversified Industrials
7 31061119 31061 2.644472e+10 159.640 310 3 981267.0 Sensitive Industrials Industrial Products Diversified Industrials
8 31061119 31061 6.061996e+09 137.320 310 3 70355.0 Sensitive Industrials Industrial Products Diversified Industrials
9 31061119 31061 5.875471e+09 45.250 310 3 286614.0 Sensitive Industrials Industrial Products Diversified Industrials
10 31061119 31061 1.542700e+10 99.900 310 3 827786.0 Sensitive Industrials Industrial Products Diversified Industrials
11 31061119 31061 4.490206e+10 70.740 310 3 3091480.0 Sensitive Industrials Industrial Products Diversified Industrials
12 31061119 31061 3.524978e+10 80.450 310 3 1300946.0 Sensitive Industrials Industrial Products Diversified Industrials
13 31061119 31061 1.970117e+09 42.300 310 3 101107.0 Sensitive Industrials Industrial Products Diversified Industrials
14 31061119 31061 1.221770e+11 14.060 310 3 53416508.0 Sensitive Industrials Industrial Products Diversified Industrials
15 31061119 31061 7.883661e+09 46.630 310 3 419584.0 Sensitive Industrials Industrial Products Diversified Industrials
16 31061119 31061 1.127931e+10 147.260 310 3 76837.0 Sensitive Industrials Industrial Products Diversified Industrials
17 31061119 31061 2.212020e+10 88.520 310 3 673308.0 Sensitive Industrials Industrial Products Diversified Industrials
18 31061119 31061 5.725331e+10 167.620 310 3 914706.0 Sensitive Industrials Industrial Products Diversified Industrials
19 31061119 31061 7.156369e+09 128.410 310 3 388657.0 Sensitive Industrials Industrial Products Diversified Industrials
20 31061119 31061 1.378940e+11 231.610 310 3 1545480.0 Sensitive Industrials Industrial Products Diversified Industrials
21 31061119 31061 8.088346e+09 139.650 310 3 114212.0 Sensitive Industrials Industrial Products Diversified Industrials
22 31061119 31061 2.420153e+10 181.895 310 3 544009.0 Sensitive Industrials Industrial Products Diversified Industrials
23 31061119 31061 1.292618e+10 71.690 310 3 777920.0 Sensitive Industrials Industrial Products Diversified Industrials
24 31061119 31061 1.285415e+09 35.950 310 3 164781.0 Sensitive Industrials Industrial Products Diversified Industrials
25 31061119 31061 3.286241e+09 74.150 310 3 116307.0 Sensitive Industrials Industrial Products Diversified Industrials
26 31061119 31061 2.325811e+10 182.040 310 3 340802.0 Sensitive Industrials Industrial Products Diversified Industrials
27 31061119 31061 2.918626e+10 283.830 310 3 181726.0 Sensitive Industrials Industrial Products Diversified Industrials
28 31061119 31061 1.118396e+10 65.200 310 3 415769.0 Sensitive Industrials Industrial Products Diversified Industrials
29 31061119 31061 1.334396e+09 31.180 310 3 76766.0 Sensitive Industrials Industrial Products Diversified Industrials
... ... ... ... ... ... ... ... ... ... ... ...
2122 10218040 10218 1.481400e+09 12.300 102 1 251523.0 Cyclical Consumer Cyclical Travel & Leisure Lodging
2123 10218040 10218 4.727448e+09 83.000 102 1 181466.0 Cyclical Consumer Cyclical Travel & Leisure Lodging
2124 10218040 10218 4.997688e+10 139.820 102 1 1010625.0 Cyclical Consumer Cyclical Travel & Leisure Lodging
2125 10218040 10218 1.162875e+10 116.610 102 1 409859.0 Cyclical Consumer Cyclical Travel & Leisure Lodging
2126 10218040 10218 9.424116e+09 79.390 102 1 719397.0 Cyclical Consumer Cyclical Travel & Leisure Lodging
2127 10218040 10218 3.740023e+09 19.560 102 1 992459.0 Cyclical Consumer Cyclical Travel & Leisure Lodging
2128 10218040 10218 2.570040e+10 81.300 102 1 1709670.0 Cyclical Consumer Cyclical Travel & Leisure Lodging
2129 10320048 10320 3.265344e+10 15.550 103 1 3880369.0 Cyclical Financial Services Banks Banks - Regional - Europe
2130 10321054 10321 5.566661e+10 163.540 103 1 933722.0 Cyclical Financial Services Brokers & Exchanges Financial Exchanges
2131 10321054 10321 1.392772e+10 83.620 103 1 294438.0 Cyclical Financial Services Brokers & Exchanges Financial Exchanges
2132 10321054 10321 4.312472e+10 74.070 103 1 2450467.0 Cyclical Financial Services Brokers & Exchanges Financial Exchanges
2133 10321054 10321 1.335892e+10 118.560 103 1 837283.0 Cyclical Financial Services Brokers & Exchanges Financial Exchanges
2134 20743094 20743 9.583987e+09 30.180 207 2 4718545.0 Defensive Utilities Utilities - Independent Power Producers Utilities - Independent Power Producers
2135 20743094 20743 2.797668e+09 55.270 207 2 242458.0 Defensive Utilities Utilities - Independent Power Producers Utilities - Independent Power Producers
2136 20743094 20743 1.790945e+09 18.300 207 2 1291256.0 Defensive Utilities Utilities - Independent Power Producers Utilities - Independent Power Producers
2137 20743094 20743 1.618580e+09 10.930 207 2 530623.0 Defensive Utilities Utilities - Independent Power Producers Utilities - Independent Power Producers
2138 20743094 20743 8.521674e+09 19.930 207 2 3537613.0 Defensive Utilities Utilities - Independent Power Producers Utilities - Independent Power Producers
2139 31062123 31062 3.210409e+09 37.840 310 3 1134661.0 Sensitive Industrials Transportation & Logistics Airports & Air Services
2140 31062123 31062 1.469003e+09 24.880 310 3 222988.0 Sensitive Industrials Transportation & Logistics Airports & Air Services
2141 31062123 31062 1.618924e+09 63.650 310 3 145819.0 Sensitive Industrials Transportation & Logistics Airports & Air Services
2142 31062123 31062 7.739870e+09 50.590 310 3 1079061.0 Sensitive Industrials Transportation & Logistics Airports & Air Services
2143 31169148 31169 1.045254e+09 7.455 311 3 2916130.0 Sensitive Technology Semiconductors Solar
2144 31169148 31169 9.600224e+08 16.600 311 3 2363973.0 Sensitive Technology Semiconductors Solar
2145 31169148 31169 7.444864e+09 71.260 311 3 1318853.0 Sensitive Technology Semiconductors Solar
2146 31169148 31169 2.418406e+09 55.075 311 3 533986.0 Sensitive Technology Semiconductors Solar
2147 31169148 31169 8.219815e+08 7.640 311 3 2014285.0 Sensitive Technology Semiconductors Solar
2148 10104005 10104 7.319173e+08 11.330 101 1 394607.0 Cyclical Basic Materials Coal Coal
2149 10104005 10104 1.967094e+09 93.730 101 1 161175.0 Cyclical Basic Materials Coal Coal
2150 10104005 10104 4.970946e+09 38.620 101 1 914020.0 Cyclical Basic Materials Coal Coal
2151 10104005 10104 1.561768e+09 29.310 101 1 510296.0 Cyclical Basic Materials Coal Coal

2152 rows × 11 columns