Hi all,
Simple rookie question, is there any way to access historical values from the built-in factors? I'm attempting to build a simple algo that buys when a stock's price rises above its upper bollinger band, but I'm having trouble figuring out the code.
#importing the factors
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.factors import BollingerBands
#using them in the make_pipeline routine
def make_pipeline()
#create the Bollinger Band factor
bb = BollingerBands(inputs = [USEquityPricing.close], window_length=20, k=2)
#create filter that returns true if on the previous trading day the price closed above the upper band
#and if the day before that the close was beneath the upper band. i.e. the price crossed over the upper BB
first_day_test = (USEquityPricing.close > bb.upper) # if the previous close is above the upper BB
# this code is incorrect, but shows the intent. I'd like to run the comparison with the penultimate day's results
second_day_test = (USEquityPricing.close[-2] < bb.upper[-2])
#and then the final filter would be when both of them are true
filter = first_day_test & second_day_test
Is there any way to access the day-before-last's factor data?
Thanks!