Briefly, what I'm trying to do right now is create a pipeline with two columns (latest close price and talib.MACD histogram value), for all stocks that pass a screen (has not been set yet) for a period of time. I was originally using the built in MovingAverageConvergenceDivergenceSignal factor, but haven't really figured out what its output is (as it doesn't agree with any of the three talib.MACD values).
Here's my pipeline:
def make_pipeline():
lastclose = USEquityPricing.close.latest
myFactor = myMACD()
return Pipeline(
columns={
'close': lastclose,
'my MACD': myFactor
}
)
...and here's that custom MACD factor:
class myMACD(CustomFactor):
# Default inputs
inputs = [USEquityPricing.close]
window_length = 27
# Compute
def compute(self, today, assets, out, close):
macd, signal, hist = talib.MACD(close[:], fastperiod=12, slowperiod=26, signalperiod=9)
out[:] = hist[-1]
...and when I call it:
result = run_pipeline(make_pipeline(), '2017-01-01', '2017-07-03')
result
... the "macd, signal, hist = talib.MACD(close[:],..." line keeps throwing the error "AssertionError: real has wrong dimensions." I'm very new to custom factors, and really don't know exactly what all the inputs are or what types they are. I've figured out that "out[:] = assets" will return the id of the stock, and that "out[:] = close[-1]" will return the last price (same as the other column). But I don't know exactly what combination of assets and close will let me run the MACD line.
I'd really appreciate any guidence. Thanks in advance.