Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Avg of Daily Returns for 30 days for all stocks in universe

I'm new to Quantopian and trying to use the research environment. I see that the pipeline gets called for one day at a time.
How would I go about getting the average of the past 30 days daily return for each stock on a daily basis?

Thanks

2 responses

This may help you in IDE:

# Average Daily Returns in pipe  
from quantopian.pipeline import factors, filters, classifiers, Pipeline  
from quantopian.pipeline.data.builtin import USEquityPricing as USEP  
from quantopian.algorithm import attach_pipeline, pipeline_output

def initialize(context):  
    schedule_function(record_mavg, date_rules.every_day(), time_rules.market_open(minutes = 65))  
    ma      = 30  
    m       = filters.Q500US()  
    returns = factors.Returns(inputs = [USEP.close], window_length = ma + 1, mask = m)  
    mavg    = returns / ma  

    attach_pipeline(Pipeline(columns = {'mavg': mavg, }, screen = m ), 'pipe')  

def record_mavg(context, data):  
    output = pipeline_output('pipe')  
    mavg = output.mavg  

Thank you!