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.
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
# 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,
}
)
peer_count_result = run_pipeline(peer_count_pipeline, '2015-03-10', '2015-03-10')
peer_count_result.head(10)
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.
# 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
)
pct_change_result = run_pipeline(pct_change_pipeline, '2015-03-10', '2015-03-10')
pct_change_result.head(10)