Notebook
In [1]:
# Imports needed for pipeline and for defining custom factors
from quantopian.pipeline import Pipeline, CustomFactor
from quantopian.research import run_pipeline

# Import whatever datasets are to be used
from quantopian.pipeline.data.builtin import USEquityPricing

# Import any built in factors and/or filters
from quantopian.pipeline.factors import Returns
from quantopian.pipeline.filters import StaticAssets, Q500US
In [2]:
class Factor_N_Days_Ago(CustomFactor):
    """
    Returns the factor value N days ago where window_length=N
    This is the price adjusted as of the current simulation day.
    """
    def compute(self, today, assets, out, close_price): 
        out[:] = close_price[0]
In [ ]:
def make_pipeline():
        
    test_securities = symbols(['AAPL'])
    base_universe = StaticAssets(test_securities)
    
    close_price = USEquityPricing.close.latest
    close_1_yr_ago_factor = Factor_N_Days_Ago(inputs=[USEquityPricing.close], window_length=252)
    close_1_yr_ago_calculated = close_price / (Returns(window_length=252) + 1.0)
    
    return Pipeline(
      columns={
        'close_price': close_price,
        'close_1_yr_ago_factor': close_1_yr_ago_factor,
        'close_1_yr_ago_calculated': close_1_yr_ago_calculated,
         },
      screen=base_universe
    )

result = run_pipeline(make_pipeline(), '2016-07-29', '2016-08-29')
result

In [ ]: