Notebook

In this notebook, we make use of the peer_count Classifier method to identify Factset RBICS Focus subsectors with low asset counts, and create a filter to throw out these equities. We also use the built-in PercentChange Factor to calculate the daily percent change in trading volume for each equity.

In [6]:
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data import EquityPricing
from quantopian.pipeline.data.factset import RBICSFocus
from quantopian.pipeline.factors import PercentChange
from quantopian.research import run_pipeline
In [7]:
# A classifier that gives the Factset RBICS Focus subsector for each equity
subsectors = RBICSFocus.l3_name.latest

# A factor that gives the number of equities that belong to each unique RBICS subsector
assets_per_subsector = subsectors.peer_count()

# Equities that belong to an RBICS subsector that contains more than 50 total assets
enough_assets = assets_per_subsector > 50

# Create a pipeline with the subsector names, the counts, and the filter
peer_count_pipeline = Pipeline(
    columns={
        'subsectors':subsectors,
        'num_per_sector':assets_per_subsector,
        'enough':enough_assets,
    }
)
In [8]:
peer_count_result = run_pipeline(peer_count_pipeline, '2015-03-10', '2015-03-10')
peer_count_result.head(10)

Pipeline Execution Time: 0.26 Seconds
Out[8]:
enough num_per_sector subsectors
2015-03-10 00:00:00+00:00 Equity(2 [ARNC]) True 61.0 Metal Products
Equity(21 [AAME]) True 137.0 Insurance
Equity(24 [AAPL]) False 37.0 Computer Hardware and Storage
Equity(25 [ARNC_PR]) False NaN None
Equity(31 [ABAX]) True 54.0 Miscellaneous Healthcare
Equity(39 [DDC]) False NaN None
Equity(41 [ARCB]) True 64.0 Cargo Transportation and Infrastructure Services
Equity(52 [ABM]) False 16.0 Business Support Services
Equity(53 [ABMD]) True 72.0 General Medical Devices
Equity(62 [ABT]) True 142.0 Other Biopharmaceuticals

We see that the number of assets in each RBICS Focus subsector varies quite a bit, and the Filter successfully flags assets belonging to industries with 50 or fewer equities.

Now we will use this Filter to screen those assets out of the next pipeline.

In [9]:
# Daily trading volume data
vol = EquityPricing.volume

# Percent change in trading volume from the previous day to the current day (window length 2)
vol_pct_change = PercentChange(inputs=[vol], window_length=2)

# Pipeline with volume and pct change, without assets belonging to RIBCS subsectors with low counts
pct_change_pipeline = Pipeline(
    columns={
        'vol':vol.latest,
        'daily_pct_change':vol_pct_change
    }, 
    screen=enough_assets
)
In [10]:
pct_change_result = run_pipeline(pct_change_pipeline, '2015-03-10', '2015-03-10')
pct_change_result.head(10)

Pipeline Execution Time: 0.55 Seconds
Out[10]:
daily_pct_change vol
2015-03-10 00:00:00+00:00 Equity(2 [ARNC]) 2.869713 70628505.0
Equity(21 [AAME]) -0.690380 1223.0
Equity(31 [ABAX]) 0.217622 164883.0
Equity(41 [ARCB]) -0.107215 197893.0
Equity(53 [ABMD]) 0.436541 305502.0
Equity(62 [ABT]) -0.409787 3605200.0
Equity(64 [GOLD]) -0.024410 18717142.0
Equity(66 [AB]) 0.266309 291836.0
Equity(67 [ADSK]) -0.280633 1009547.0
Equity(100 [IEP]) -0.310255 51735.0