Pipeline output can be opened in the Data Browser. This allows you to view plots of the pipeline columns you calculated and visualize how the calculated indicators change over time for any given security. The Data Browser also makes it easy to see a breakdown of the types of securities that are passing your pipeline screen so that you can validate your pipeline logic. Are the results concentrated in certain sectors? Do the results include security types that you would rather exclude?
from zipline.pipeline import Pipeline, EquityPricing, master
from zipline.pipeline.factors import SimpleMovingAverage
# import our InitialUniverse and TradableStocksUS functions
from codeload.pipeline_tutorial.tradable_stocks import InitialUniverse, TradableStocksUS
To demonstrate the Data Browser integration, let's create a Pipeline that includes 3 columns:
.as_factor()
method to convert the boolean filter (True or False) into 1 or 0.The universe for the analysis will be the TradableStocksUS
universe.
def make_pipeline():
initial_universe = InitialUniverse()
universe = TradableStocksUS()
# 200-day close price average.
mean_200 = SimpleMovingAverage(inputs=EquityPricing.close, window_length=200, mask=universe)
return Pipeline(
columns={
'close': EquityPricing.close.latest,
'200_ma': mean_200,
'above_200_ma': (EquityPricing.close.latest > mean_200).as_factor()
},
initial_universe=initial_universe,
screen=universe
)
Next, we run the pipeline for the date range of interest:
from zipline.research import run_pipeline
results = run_pipeline(make_pipeline(), start_date="2010-01-05", end_date="2011-01-05")
We can then open the pipeline output in the Data Browser by calling the IPython magic command %browse
followed by the name of the results DataFrame:
%browse results
See the video below for a walk-through:
from IPython.display import VimeoVideo
VimeoVideo('920097406', width=600, height=450)