I'm trying to write my own custom factor. I'm trying to run a function fit_test onto each stock in the pipeline and return the data to a column in the pipeline. In the docs,I see simple implementation of Momentum. I did'nt see anything for more complicated customfactors.I'm trying to play around with various models. I'm not sure if I'm doing this correctly.
I create my pipeline
# Attach data pipelines
p1=attach_pipeline(
make_pipeline(),
'data_pipe'
)
my_factor = test(inputs=[USEquityPricing.close], window_length=50)
p1.add(my_factor, 'forecast')
I create my custom factor. I'm trying to run the function fit_test on each stock for the last 30 days of price data
class test(CustomFactor):
def compute(self, today, asset_ids, out2, values):
out=[]
len_values=len(values)
for i in xrange(0,len_values):
column=[item[i] for item in values]
cleanedList = [x for x in column if str(x) != 'nan']
if len(cleanedList) > 5:
yhat = 0
param1,param2,param3 = fit_test(cleanedList)
len_cleanedlist=len(cleanedList)
yhat = ....
out.append(yhat)
out2=out
print out2
return out2
I test my code using this:
all=context.output.query('yesterday_close>0')
print all
The "print out2" displays data with valid numbers.
The "print all" displays all the forecast as NaN.
Any pointers on how to write something like this. Thanks in advance.