I'm having trouble making a custom factor iterate over an input with a window length. I think I'm missing something simple, so any pointers are greatly appreciated.
I'm just trying to make a factor that returns 1 if a new Higher Lowest Low occurs, and 0 if a new Lower Highest High. I made a factor that returns the Highest High and Lowest Low over the last 10 days. Now I want to use the result (with window length 2) as the input to another factor that will check if the latest highest high or lowest low are lower or higher than the previous one.
My problem is that I can't figure out how to iterate through the inputs on the HLorLH factor below:
class HHLL(CustomFactor):
# Define inputs
inputs = [USEquityPricing.high, USEquityPricing.low]
outputs = ['hh','ll']
window_safe = True
# Set window_length to whatever number of days to lookback as a default
# Specify and name the different outputs.
def compute(self, today, assets, out, high,low):
# Note that close is a numpy array and NOT a pandas dataframe
out.hh[:] = np.nanmax(high,axis=0)
out.ll[:] = np.nanmin(low,axis=0)
class HLorLH(CustomFactor):
def compute(self, today, assets, out, hh, ll):
log.info(hh)
def make_pipeline():
base_universe = Q500US()
close_price = USEquityPricing.close.latest
hh, ll = HHLL(window_length=10)
order = Order(inputs=[hh,ll], window_length=2)
return Pipeline(columns={
'close_price': close_price,
'order': order
}, screen=(base_universe))