zipline run_pipeline和位置参数

时间:2017-07-11 09:40:30

标签: python zipline

我使用Zipline-1.1.1,Python3.4.6创建动态股票选择器,如下所示:

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

我用:

初始化一个管道对象
my_pipe = make_pipeline()

但是当我尝试填充Pipeline时,它失败了:

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'

我无法弄清楚出了什么问题,非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您正在使用this库。

据我所知,为了能够使用run_pipeline方法,您必须instantiate之前使用管道引擎,例如SimplePipelineEngine。你需要它,因为PipelineEngine是一个类,甚至是抽象类,而不是一个对象。

因此,您必须创建SimplePipelineEngine类的对象,然后在其上调用run_pipeline。你可以这样做:

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')

当然,您必须先创建your_loader等。

HereSimplePipelineEngine用法的示例。我希望它会有所帮助。