Hello there
Here is a stripped down version of a custom factor my Algo uses. This gets the max and the min from two series (daily High and daily low) for each stock and returns the difference found in that time window.
The "days" argument is used to lag the window backwards.
def Difference(days, **kwargs):
kwargs['window_length'] += days
class diff_calc(CustomFactor):
def compute(self, today, assets, out, high,low):
out[:] = np.nanmax(high[:self.window_length-days], axis=0)) - np.nanmin(low[:self.window_length-days], axis=0))
return diff_calc(**kwargs)
Would it also be possible to also return the dates of the max value and the date of the min value which are returned?
My use case for this is to classify whether the max came before the min, or vice versa.
Any hints tips appreciated!