This is what I have plus some:
class Previous(CustomFactor):
# Returns value of input x trading days ago where x is the window_length
# Both the inputs and window_length must be specified as there are no defaults
def compute(self, today, assets, out, inputs):
out[:] = inputs[0]
class SCORE(CustomFactor):
window_length = 365
roa_1_year_ago = Previous(inputs = [morningstar.operation_ratios.roa], window_length = 252)
roa_1_year_ago.window_safe = True
inputs = [
morningstar.operation_ratios.roa.latest,
roa_1_year_ago,
]
def compute(self, today, assets, out, roa, roa_1_year_ago):
score = 0
#----------------------------------------------------------------------------------------------------
if (roa > 0): score += 1
if (roa > roa_1_year_ago): score +=1
#----------------------------------------------------------------------------------------------------
out[:] = score
when I run it, I get this error which involves what you said about window_safe:
NonWindowSafeInput: Can't compute windowed expression FS_SCORE([Latest(...), Latest(...), Latest(...), Latest(...), Previous(...), Previous(...), Latest(...), Previous(...), Latest(...), Latest(...), Previous(...), Previous(...), Latest(...), Latest(...), Previous(...), Previous(...), Latest(...), Previous(...)], 365) with windowed input Latest([operation_ratios<US>.roa], 1).
This error seems odd to me because I have never had to set the Latest to window safe before:
should i declare a variable to hold it before the input block and see it to window_safe there and load it into input like the Previous() variables?
Full Error:
```
NonWindowSafeInputTraceback (most recent call last)
in ()
241
242
--> 243 my_pipe = make_pipeline()
244 result = run_pipeline(my_pipe, '2005-01-01', '2006-01-01').dropna()
245 print 'Head: ', result.head(20)
in make_pipeline()
220 close_price_below_SMA = (latest_close < mean_close_200)
221
--> 222 score = SCORE()
223 score.window_safe = True
224
/build/src/qexec_repo/zipline_repo/zipline/pipeline/mixins.pyc in new(cls, inputs, outputs, window_length, mask, dtype, missing_value, ndim, **kwargs)
138 missing_value=missing_value,
139 ndim=ndim,
--> 140 **kwargs
141 )
142
/build/src/qexec_repo/zipline_repo/zipline/pipeline/term.pyc in new(cls, inputs, outputs, window_length, mask, domain, *args, **kwargs)
508 window_length=window_length,
509 domain=domain,
--> 510 *args, **kwargs
511 )
512
/build/src/qexec_repo/zipline_repo/zipline/pipeline/term.pyc in new(cls, domain, dtype, missing_value, window_safe, ndim, *args, **kwargs)
133 ndim=ndim,
134 params=params,
--> 135 *args, **kwargs
136 )
137 return new_instance
/build/src/qexec_repo/zipline_repo/zipline/pipeline/term.pyc in _init(self, inputs, outputs, window_length, mask, *args, **kwargs)
516 self.window_length = window_length
517 self.mask = mask
--> 518 return super(ComputableTerm, self)._init(*args, **kwargs)
519
520 @classmethod
/build/src/qexec_repo/zipline_repo/zipline/pipeline/term.pyc in _init(self, domain, dtype, missing_value, window_safe, ndim, params)
275 # should set this flag to True.
276 self._subclass_called_super_validate = False
--> 277 self._validate()
278 assert self._subclass_called_super_validate, (
279 "Term._validate() was not called.\n"
/build/src/qexec_repo/zipline_repo/zipline/pipeline/factors/factor.pyc in _validate(self)
1567 def _validate(self):
1568 try:
-> 1569 super(CustomFactor, self)._validate()
1570 except UnsupportedDataType:
1571 if self.dtype in CLASSIFIER_DTYPES:
/build/src/qexec_repo/zipline_repo/zipline/pipeline/mixins.pyc in _validate(self)
40 """
41 def _validate(self):
---> 42 super(PositiveWindowLengthMixin, self)._validate()
43 if not self.windowed:
44 raise WindowLengthNotPositive(window_length=self.window_length)
/build/src/qexec_repo/zipline_repo/zipline/pipeline/mixins.pyc in _validate(self)
85
86 def _validate(self):
---> 87 super(RestrictedDTypeMixin, self)._validate()
88 assert self.ALLOWED_DTYPES is not NotSpecified, (
89 "ALLOWED_DTYPES not supplied on subclass "
/build/src/qexec_repo/zipline_repo/zipline/pipeline/term.pyc in _validate(self)
582 for child in self.inputs:
583 if not child.window_safe:
--> 584 raise NonWindowSafeInput(parent=self, child=child)
585
586 def _compute(self, inputs, dates, assets, mask):
NonWindowSafeInput: Can't compute windowed expression FS_SCORE([Latest(...), Latest(...), Latest(...), Latest(...), Previous(...), Previous(...), Latest(...), Previous(...), Latest(...), Latest(...), Previous(...), Previous(...), Latest(...), Latest(...), Previous(...), Previous(...), Latest(...), Previous(...)], 365) with windowed input Latest([operation_ratios.roa], 1).