Hi,
I can't wrap my head around how I can code a simple moving average crossover in pipeline, with the encodings [1,0,-1].
This was my first attempt, however it doesn't execute and throws me an error. I must say debugging in Pipeline is almost impossible when I can't inspect the objects from which it creates the calculations.
class SMA_yesterday(CustomFactor):
inputs = [USEquityPricing.close]
def compute(self, today, assets, out, close):
out[:] = np.nanmean(close[:-1], axis=0)
class Crossover(CustomFactor):
window_length=31
inputs=[USEquityPricing.close]
def compute(self, today, assets, out, inputs):
mean_10_today = SimpleMovingAverage(inputs=inputs,window_length=10, mask=QTradableStocksUS())
mean_30_today = SimpleMovingAverage(inputs=inputs,window_length=30, mask=QTradableStocksUS())
mean_10_yesterday = SMA_yesterday(inputs=inputs,window_length=11, mask=QTradableStocksUS())
mean_30_yesterday = SMA_yesterday(inputs=inputs,window_length=31, mask=QTradableStocksUS())
output=np.where(
(mean_10_today>mean_30_today)&(mean_10_yesterday<mean_30_yesterday),1,
np.where(
(mean_10_today<mean_30_today)&(mean_10_yesterday>mean_30_yesterday),-1,0))
out[:] = output