zipline run_pipeline 和位置参数

zipline run_pipeline and positional arguments

我正在使用 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()

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

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'

我不知道哪里出了问题,非常感谢任何帮助。

如果我没理解错的话,您正在使用 this 库。

据我从该代码中可以看出,要能够使用 run_pipeline 方法,您必须先 instantiate on of pipeline engines,例如SimplePipelineEngine。你需要它,因为 PipelineEngine 是一个 class,甚至是抽象的 class,而不是一个对象。

因此您必须创建 SimplePipelineEngine class 的 对象 ,然后在其上调用 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 用法的示例。希望对你有所帮助。