ENH: Compute engine architecture for FFC API.

This patch lays the groundwork for a compute engine designed to
facilitate construction of factor-based universe screening and portfolio
allocation.  It contains:

A new module, `zipline.modelling`, containing entities that can be used
to express computations as dependency graphs.  Each node in such a graph
is an instance of the base `Term` class, defined in
`zipline.modelling.term`.  Dependency graphs are executed by instances
of `FFCEngine`, defined in `zipline.modelling.engine`.

A new module, `zipline.data.ffc`, containing loaders and dataset
definitions for inputs to the modelling API.

New `TradingAlgorithm` api methods: `add_factor`, and `add_filter`.
These methods can only be called from `initialize`, and are used to
inform the algorithm that each day it should compute the given terms.
Computed factor results are made available through a new attribute of
the `data` object in `before_trading_start` and `handle_data`.  Computed
filter results control which assets are available in the factor matrix
on each day.
This commit is contained in:
Scott Sanderson
2015-07-29 12:30:46 -04:00
parent 6b72b60cde
commit ef4f642e62
54 changed files with 8048 additions and 51 deletions
+22 -1
View File
@@ -23,9 +23,10 @@ from unittest import TestCase
import numpy as np
import pandas as pd
from zipline.api_support import ZiplineAPI
from zipline.assets import AssetFinder
from zipline.utils.control_flow import nullctx
from zipline.utils.test_utils import (
nullctx,
setup_logger,
teardown_logger
)
@@ -150,6 +151,26 @@ class TestMiscellaneousAPI(TestCase):
def tearDown(self):
teardown_logger(self)
def test_zipline_api_resolves_dynamically(self):
# Make a dummy algo.
algo = TradingAlgorithm(
initialize=lambda context: None,
handle_data=lambda context, data: None,
sim_params=self.sim_params,
)
# Verify that api methods get resolved dynamically by patching them out
# and then calling them
for method in algo.all_api_methods():
name = method.__name__
sentinel = object()
def fake_method(*args, **kwargs):
return sentinel
setattr(algo, name, fake_method)
with ZiplineAPI(algo):
self.assertIs(sentinel, getattr(zipline.api, name)())
def test_get_environment(self):
expected_env = {
'arena': 'backtest',