本文整理汇总了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)
示例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)
示例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")
示例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")
示例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)
示例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)