当前位置: 首页>>代码示例>>Python>>正文


Python Pipeline.set_screen方法代码示例

本文整理汇总了Python中zipline.pipeline.Pipeline.set_screen方法的典型用法代码示例。如果您正苦于以下问题:Python Pipeline.set_screen方法的具体用法?Python Pipeline.set_screen怎么用?Python Pipeline.set_screen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在zipline.pipeline.Pipeline的用法示例。


在下文中一共展示了Pipeline.set_screen方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: initialize

# 需要导入模块: from zipline.pipeline import Pipeline [as 别名]
# 或者: from zipline.pipeline.Pipeline import set_screen [as 别名]
def initialize(context):

    pipe = Pipeline()
    attach_pipeline(pipe, 'example')

    # Note that we don't call add_factor on these Factors.
    # We don't need to store intermediate values if we're not going to use them
    sma_short = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=30)
    sma_long = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=100)

    sma_val = sma_short/sma_long

    # Construct the custom factor
    mkt_cap = MarketCap()

    # Create and apply a filter representing the top 500 equities by MarketCap
    # every day.
    mkt_cap_top_500 = mkt_cap.top(500)

    remove_penny_stocks = sma_short > 1.0

    pipe.add(sma_val, 'sma_val')
    pipe.add(mkt_cap, 'mkt_cap')
    # Use mkt_cap_top_500 as a mask on rank
    pipe.add(sma_val.rank(mask=mkt_cap_top_500), 'sma_rank')

    # Use multiple screens to narrow the universe
    pipe.set_screen(mkt_cap.top(500) & remove_penny_stocks)
开发者ID:mequanta,项目名称:z-runner,代码行数:30,代码来源:creating_custom_factors.py

示例2: initialize

# 需要导入模块: from zipline.pipeline import Pipeline [as 别名]
# 或者: from zipline.pipeline.Pipeline import set_screen [as 别名]
def initialize(context):

    # Create, register and name a pipeline in initialize.
    pipe = Pipeline()
    attach_pipeline(pipe, 'example')

    # Construct a simple moving average factor and add it to the pipeline.
    sma_short = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=10)
    pipe.add(sma_short, 'sma_short')

    # Set a screen on the pipelines to filter out securities.
    pipe.set_screen(sma_short > 1.0)
开发者ID:mequanta,项目名称:z-runner,代码行数:14,代码来源:using_pipelines.py

示例3: initialize

# 需要导入模块: from zipline.pipeline import Pipeline [as 别名]
# 或者: from zipline.pipeline.Pipeline import set_screen [as 别名]
        def initialize(context):
            pipeline = Pipeline()
            context.vwaps = []
            for length in vwaps:
                name = vwap_key(length)
                factor = VWAP(window_length=length)
                context.vwaps.append(factor)
                pipeline.add(factor, name=name)

            filter_ = USEquityPricing.close.latest > 300
            pipeline.add(filter_, "filter")
            if set_screen:
                pipeline.set_screen(filter_)

            attach_pipeline(pipeline, "test")
开发者ID:RoyHsiao,项目名称:zipline,代码行数:17,代码来源:test_pipeline_algo.py

示例4: initialize

# 需要导入模块: from zipline.pipeline import Pipeline [as 别名]
# 或者: from zipline.pipeline.Pipeline import set_screen [as 别名]
def initialize(context):

    pipe = Pipeline()
    attach_pipeline(pipe, "example")

    sma_short = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=30)
    sma_long = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=100)

    # Combined factors to create new factors
    sma_val = sma_short / sma_long

    # Create and apply a screen to remove penny stocks
    remove_penny_stocks = sma_short > 1.0
    pipe.set_screen(remove_penny_stocks)

    pipe.add(sma_short, "sma_short")
    pipe.add(sma_long, "sma_long")
    pipe.add(sma_val, "sma_val")
    # Rank a factor using a mask to ignore the values we're
    # filtering out by passing mask=remove_penny_stocks to rank.
    pipe.add(sma_val.rank(mask=remove_penny_stocks), "sma_rank")
开发者ID:mequanta,项目名称:z-runner,代码行数:23,代码来源:combining_and_ranking.py

示例5: test_set_screen

# 需要导入模块: from zipline.pipeline import Pipeline [as 别名]
# 或者: from zipline.pipeline.Pipeline import set_screen [as 别名]
    def test_set_screen(self):
        f, g = SomeFilter(), SomeOtherFilter()

        p = Pipeline()
        self.assertEqual(p.screen, None)

        p.set_screen(f)
        self.assertEqual(p.screen, f)

        with self.assertRaises(ValueError):
            p.set_screen(f)

        p.set_screen(g, overwrite=True)
        self.assertEqual(p.screen, g)

        with self.assertRaises(TypeError) as e:
            p.set_screen(f, g)

        message = e.exception.args[0]
        self.assertIn("expected a value of type bool or int for argument 'overwrite'", message)
开发者ID:testmana2,项目名称:zipline,代码行数:22,代码来源:test_pipeline.py

示例6: test_set_screen

# 需要导入模块: from zipline.pipeline import Pipeline [as 别名]
# 或者: from zipline.pipeline.Pipeline import set_screen [as 别名]
    def test_set_screen(self):
        f, g = SomeFilter(), SomeOtherFilter()

        p = Pipeline()
        self.assertEqual(p.screen, None)

        p.set_screen(f)
        self.assertEqual(p.screen, f)

        with self.assertRaises(ValueError):
            p.set_screen(f)

        p.set_screen(g, overwrite=True)
        self.assertEqual(p.screen, g)
开发者ID:kczxl,项目名称:zipline,代码行数:16,代码来源:test_pipeline.py


注:本文中的zipline.pipeline.Pipeline.set_screen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。