I want to be able to compare the current price with yesterday's SMA so I can tell if the price has crossed it, then use that as a filter. I can't figure out how to do that with the dataset and pipeline framework.
Any help would be great
I want to be able to compare the current price with yesterday's SMA so I can tell if the price has crossed it, then use that as a filter. I can't figure out how to do that with the dataset and pipeline framework.
Any help would be great
Hello,
Create a custom factor with two outputs, the current value and the previous one:
class SMA(CustomFactor):
inputs = [USEquityPricing.close]
outputs = ['value', 'value_p']
def compute(self, today, assets, out, close):
N = self.window_length -1
sma_vector = talib.MA(close, timeperiod=N)
out.value[:] = sma_vector [-1]
out.value_p[:] = sma_vector [-2]