Creating a Pipeline

In this lesson, we will take a look at creating an empty pipeline. First, let's import the Pipeline class:

In [1]:
from zipline.pipeline import Pipeline

In a new cell, let's define a function to create our pipeline. Wrapping our pipeline creation in a function sets up a structure for more complex pipelines that we will see later on. For now, this function simply returns an empty pipeline:

In [2]:
def make_pipeline():
    return Pipeline()

In a new cell, let's instantiate our pipeline by running make_pipeline():

In [3]:
my_pipe = make_pipeline()

Running a Pipeline

Now that we have a reference to an empty Pipeline, my_pipe, let's run it to see what it looks like. Before running our pipeline, we first need to import run_pipeline, a research-only function that allows us to run a pipeline over a specified time period.

In [4]:
from zipline.research import run_pipeline

Since we will be using the same data bundle repeatedly in this tutorial, we can set it as the default bundle to avoid always having to type the name of the bundle in each call to run_pipeline:

In [5]:
from quantrocket.zipline import set_default_bundle
set_default_bundle("usstock-1d-bundle")
Out[5]:
{'status': 'successfully set default bundle'}

Let's run our pipeline for one day (2015-05-05) with run_pipeline and display it.

In [6]:
result = run_pipeline(my_pipe, start_date='2015-05-05', end_date='2015-05-05')

A call to run_pipeline returns a pandas DataFrame indexed by date and security. Let's see what the empty pipeline looks like:

In [7]:
result
Out[7]:
2015-05-05 00:00:00+00:00Equity(FIBBG000C2V3D6 [A])
Equity(FIBBG00B3T3HD3 [AA])
Equity(QI000000004076 [AABA])
Equity(FIBBG006T1NZ18 [AAC])
Equity(FIBBG001B9VR83 [AAC])
Equity(FIBBG000V2S3P6 [AACG])
Equity(FIBBG000BDYRW6 [AADR])
Equity(FIBBG002MYG6B3 [AAIT])
Equity(FIBBG005P7Q881 [AAL])
Equity(FIBBG003PNL136 [AAMC])
Equity(FIBBG000B9XB24 [AAME])
Equity(FIBBG000D9V7T4 [AAN])
Equity(FIBBG000D6VW15 [AAOI])
Equity(FIBBG000C2LZP3 [AAON])
Equity(FIBBG000F7RCJ1 [AAP])
Equity(FIBBG008651TF3 [AAPC])
Equity(FIBBG000B9XRY4 [AAPL])
Equity(FIBBG00161BCR0 [AAT])
Equity(FIBBG000DGFSY4 [AAU])
Equity(FIBBG000C5QZ62 [AAV])
Equity(FIBBG000Q57YP0 [AAWW])
Equity(FIBBG000G6GXC5 [AAXJ])
Equity(FIBBG000BHJWG1 [AAXN])
Equity(FIBBG000B9WM03 [AB])
Equity(FIBBG000CP4WX9 [ABAX])
Equity(FIBBG000DK5Q25 [ABB])
Equity(FIBBG0025Y4RY4 [ABBV])
Equity(FIBBG000MDCQC2 [ABC])
Equity(FIBBG000CDY3H5 [ABCB])
Equity(FIBBG000Q05Q43 [ABCD])
...
Equity(FIBBG004HQMCJ4 [ZIONN])
Equity(FIBBG0043FW0J8 [ZIONO])
Equity(FIBBG000002FJ2 [ZIONP])
Equity(FIBBG000RMX9Z7 [ZIONW])
Equity(FIBBG000PQQH62 [ZIONZ])
Equity(FIBBG000FWCC57 [ZIOP])
Equity(FIBBG0019HMFX6 [ZIV])
Equity(FIBBG000H04C72 [ZIXI])
Equity(FIBBG006MJFPW3 [ZJPN])
Equity(FIBBG007XHN059 [ZLRG])
Equity(FIBBG001J2P4Y9 [ZLTQ])
Equity(FIBBG005WX1JJ7 [ZMLP])
Equity(FIBBG000RFZLM7 [ZN])
Equity(FIBBG000VD6768 [ZNGA])
Equity(FIBBG000BXQ7R1 [ZNH])
Equity(FIBBG0064MY238 [ZOES])
Equity(FIBBG006G0NHM1 [ZPIN])
Equity(FIBBG000FTMSF7 [ZQK])
Equity(FIBBG000PN8QP8 [ZROZ])
Equity(FIBBG006TL19Y0 [ZSAN])
Equity(FIBBG000F9CW36 [ZSL])
Equity(FIBBG007XHMYS1 [ZSML])
Equity(FIBBG003LFL2G1 [ZSPH])
Equity(FIBBG000BXB8X8 [ZTR])
Equity(FIBBG0039320N9 [ZTS])
Equity(FIBBG001Z7M393 [ZU])
Equity(FIBBG000PYX812 [ZUMZ])
Equity(FIBBG000C3CQP1 [ZVO])
Equity(FIBBG001NFC923 [ZX])
Equity(FIBBG00VT0KNC3 [MTCH])

8422 rows × 0 columns

The output of an empty pipeline is a DataFrame with no columns. In this example, our pipeline has an index made up of all 8000+ securities (truncated in the display) for May 5th, 2015, but doesn't have any columns.

In the following lessons, we'll take a look at how to add columns to our pipeline output, and how to filter down to a subset of securities.


Next Lesson: Factors