Please help me.
I am trying to get this pipeline to filter stocks that are up 4% or more for the day and are priced between $1 - $10.
I am having trouble. Been trying to program this for days! Please does someone have the answer?
Code is below.
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.factors import SimpleMovingAverage
def initialize(context):
# Create and attach an empty Pipeline.
pipe = Pipeline()
pipe = attach_pipeline(pipe, name='my_pipeline')
# Construct Factors.
change_4 = returns(inputs=[USEquityPricing.close], window_length=2)
# Construct a Filter.
prices_under_1 = (price < 1)
prices_over_10 = (price > 10)
# Register outputs.
pipe.add(change_4, 'change_4')
# Remove rows for which the Filter returns False.
pipe.set_screen(prices_under_1)
pipe.set_screen(prices_over_10)
def before_trading_start(context, data):
# Access results using the name passed to attach_pipeline
.
results = pipeline_output('my_pipeline')
print results.head(5)
# Define a universe with the results of a Pipeline.
# Take the first 25 assets by gain above 4%.
update_universe(results.sort('change_4').index[:25])
def handle_data(cdontext, data):
pass