ENH: Pipeline API

- Adds `zipline.pipeline.Pipeline`, a new user-facing class for managing
  pipelines of Modeling API expressions.

- Adds `attach_pipeline` and `drain_pipeline` as API methods

- Removes `add_factor` and `add_filter` as API methods.  These have been
  replaced two new methods on `Pipeline`: `add`, and `apply_screen`.

- Adding a `Filter` as a column no longer implicitly truncates rows from
  the Modelling API output.  It simply causes a new column, of dtype
  `bool` to show up in the output. Removal of rows is now handled by the
  new `apply_screen` method of `Pipeline`.

- Refactors the existing Modeling API tests to reflect the new APIs.
This commit is contained in:
Scott Sanderson
2015-10-01 18:03:53 -04:00
parent 0e0dec49e5
commit 8e59d12daf
12 changed files with 782 additions and 296 deletions
+5 -6
View File
@@ -10,7 +10,6 @@ from six import iteritems
from zipline.finance.trading import TradingEnvironment
from zipline.modelling.engine import SimpleFFCEngine
from zipline.modelling.graph import TermGraph
from zipline.modelling.term import AssetExists
from zipline.utils.pandas_utils import explode
from zipline.utils.test_utils import make_simple_asset_info, ExplodingObject
@@ -72,15 +71,15 @@ class BaseFFCTestCase(TestCase):
"""Default shape for methods that build test data."""
return self.__mask.shape
def run_terms(self, terms, initial_workspace, mask=None):
def run_graph(self, graph, initial_workspace, mask=None):
"""
Compute the given terms, seeding the workspace of our FFCEngine with
Compute the given TermGraph, seeding the workspace of our engine with
`initial_workspace`.
Parameters
----------
terms : dict
Mapping from termname -> term object.
graph : zipline.pipeline.graph.TermGraph
Graph to run.
initial_workspace : dict
Initial workspace to forward to SimpleFFCEngine.compute_chunk.
mask : DataFrame, optional
@@ -104,7 +103,7 @@ class BaseFFCTestCase(TestCase):
dates, assets, mask_values = explode(mask)
initial_workspace.setdefault(AssetExists(), mask_values)
return engine.compute_chunk(
TermGraph(terms),
graph,
dates,
assets,
initial_workspace,