I copied Max's code from:
Then I added a trivial
preprocess
function that prints and returns a value only.
The print statement suggests that the custom factor is outputting a scalar, not a vector as one might expect.
What's going on?
def preprocess(a):
print a
return a
class TEM(CustomFactor):
"""
TEM = standard deviation of past 6 quarters' reports
"""
window_length = 390
def compute(self, today, assets, out, asof_date, capex, total_assets):
values = capex/total_assets
for column_ix in range(asof_date.shape[1]):
_, unique_indices = np.unique(asof_date[:, column_ix], return_index=True)
quarterly_values = values[unique_indices, column_ix]
if len(quarterly_values) < 6:
quarterly_values = np.hstack([
np.repeat([np.nan], 6 - len(quarterly_values)),
quarterly_values,
])
out[column_ix] = preprocess(np.std(quarterly_values[-6:]))