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 quantopian.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 quantopian.research import run_pipeline

Let's run our pipeline for one day (2015-05-05) with run_pipeline and display it. Note that the 2nd and 3rd arguments are the start and end dates of the simulation, respectively.


In [5]:
result = run_pipeline(my_pipe, '2015-05-05', '2015-05-05')

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


In [6]:
result


Out[6]:
2015-05-05 00:00:00+00:00 Equity(2 [AA])
Equity(21 [AAME])
Equity(24 [AAPL])
Equity(25 [AA_PR])
Equity(31 [ABAX])
Equity(39 [DDC])
Equity(41 [ARCB])
Equity(52 [ABM])
Equity(53 [ABMD])
Equity(62 [ABT])
Equity(64 [ABX])
Equity(66 [AB])
Equity(67 [ADSK])
Equity(69 [ACAT])
Equity(70 [VBF])
Equity(76 [TAP])
Equity(84 [ACET])
Equity(86 [ACG])
Equity(88 [ACI])
Equity(100 [IEP])
Equity(106 [ACU])
Equity(110 [ACXM])
Equity(112 [ACY])
Equity(114 [ADBE])
Equity(117 [AEY])
Equity(122 [ADI])
Equity(128 [ADM])
Equity(134 [SXCL])
Equity(149 [ADX])
Equity(153 [AE])
...
Equity(48961 [NYMT_O])
Equity(48962 [CSAL])
Equity(48963 [PAK])
Equity(48969 [NSA])
Equity(48971 [BSM])
Equity(48972 [EVA])
Equity(48981 [APIC])
Equity(48989 [UK])
Equity(48990 [ACWF])
Equity(48991 [ISCF])
Equity(48992 [INTF])
Equity(48993 [JETS])
Equity(48994 [ACTX])
Equity(48995 [LRGF])
Equity(48996 [SMLF])
Equity(48997 [VKTX])
Equity(48998 [OPGN])
Equity(48999 [AAPC])
Equity(49000 [BPMC])
Equity(49001 [CLCD])
Equity(49004 [TNP_PRD])
Equity(49005 [ARWA_U])
Equity(49006 [BVXV])
Equity(49007 [BVXV_W])
Equity(49008 [OPGN_W])
Equity(49009 [PRKU])
Equity(49010 [TBRA])
Equity(49131 [OESX])
Equity(49259 [ITUS])
Equity(49523 [TLGT])

8236 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.