Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Comparing today's open vs yesterday's close

Hi,

For a set of stocks, I'm wondering how to compare today's open vs yesterday's close. I understand that pipeline doesn't work for intraday comparisons, so it may need to be done in handle_data.

here's what i have so far. Things error out for line today_open=...

TypeError: Expected assets argument to be of type or iterable of type Asset, ContinuousFuture, basestring

Also i'm sure there's an easier way to pull in yesterday's close, but wasn't sure how to do that.

Thanks!

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):  
    pipe = Pipeline()  
    attach_pipeline(pipe, name='my_pipeline')  
    sma_1 = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=1)  
    pipe.add(sma_1, name='sma_1')  
    schedule_function(record_vars, date_rules.every_day(), time_rules.market_close())  


def before_trading_start(context, data):  
    context.security_list = pipeline_output('my_pipeline')  
def handle_data(context, data):  

    for index, row in context.security_list.iterrows():  
        print row.iloc[0]

        today_open = data.history(context.security_list.loc[index], fields="open", bar_count=1, frequency="1d")  
        print today_open