This is the first program I've written in probably 3ish years. I had moderate experience programming back in the day, but have basically forgotten most of it to the point that I can understand most examples but can't create them at all.
Anyways, I'm trying to create an algorithm that invests in stocks with RSIs above 50. I've not even attempted rebalancing yet, and I can't seem to figure out how to create an order to buy all of the securities that have RSIs above 50. The program fails at the symbol(stock).
Can someone help me to figure out what I'm doing wrong?
#Determine which stocks to invest in based on RSI and invests in them
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 RSI
def initialize(context):
pipe = Pipeline()
attach_pipeline(pipe, name='my_pipeline')
RSI_Holder = RSI(inputs=[USEquityPricing.close], window_length=15)
reduced_universe = (RSI_Holder>50)
pipe.set_screen(reduced_universe)
pipe.add(RSI_Holder, name="RSI_Holder")
pipe.add(reduced_universe, name='reduced_universe')
def before_trading_start(context, data):
context.output = pipeline_output('my_pipeline')
context.secs = context.output[context.output['reduced_universe']]
context.long_list = context.output.sort(['reduced_universe'], ascending=True)
#print results.head(5)
print context.secs
update_universe(context.output)
#print results
#"""
def handle_data(context, data):
for stock in context.long_list:
stk = symbol(stock)
order(stk, 1)