pythonzipline

zipline run_pipeline and positional arguments


I'm using Zipline-1.1.1, Python3.4.6 to create a dynamic stock selector as follows:

from zipline.pipeline import Pipeline, engine
from zipline.pipeline.factors import AverageDollarVolume, Returns

def make_pipeline():
    dollar_volume = AverageDollarVolume(window_length=1)
    high_dollar_volume = dollar_volume.percentile_between(N, 100)
    recent_returns = Returns(window_length=N, mask=high_dollar_volume)
    low_returns = recent_returns.percentile_between(0, n)
    high_returns = recent_returns.percentile_between(N, 100)
    pipe_columns = {
        'low_returns': low_returns,
        'high_returns': high_returns,
        'recent_returns': recent_returns,
        'dollar_volume': dollar_volume
    }
    pipe_screen = (low_returns | high_returns)
    pipe = Pipeline(columns=pipe_columns, screen=pipe_screen)
    return pipe

I initialize a pipeline object with:

my_pipe = make_pipeline()

But when I try to populate the Pipeline, it fails with:

result = engine.PipelineEngine.run_pipeline(my_pipe, '2017-07-10', '2017-07-11')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    result = engine.PipelineEngine.run_pipeline(my_pipe, '2017-07-10', '2017-07-11')
TypeError: run_pipeline() missing 1 required positional argument: 'end_date'

I can't figure out what is wrong, any help is much appreciated.


Solution

  • If I understand correctly, you're using this library.

    As far as I can see from that code, to be able to use run_pipeline method you have to instantiate on of pipeline engines before, e.g. SimplePipelineEngine. You need that because PipelineEngine is a class, even abstract class, not an object.

    So you have to create an object of SimplePipelineEngine class and then call run_pipeline on it. You can do it this way:

    your_engine = SimplePipelineEngine(get_loader=your_loader, calendar=your_calendar, asset_finder=your_asset_finder)
    your_eninge.run_pipeline(my_pipe, '2017-07-10', '2017-07-11')
    

    Of course you have to create your_loader etc. first.

    Here is example of SimplePipelineEngine usage. I hope it will help.