This factor should be able to find if the low price of any 3 consecutive days within the 20 days is within very close proximity. It should scan this for every security and trail backwards around 20 times.
So it sums the low price of three previous days and finds a mean.
If the difference between the first day and the mean is lower than the arbitrary value of 0.15 then the variable increment (that is like a rank score) should increase by 1.
The days increment backwards so that it scans first -1, -2, -3 days, then -2, -3, -4 days etc.
The result I get every time is just 1 whereas it should vary for 520 stocks I got the result for. Pulling the increment = 0 variable out of the while loop results in the out[:] increment being always 19. I checked the delta_low_three value and it varies greatly and should produce a value other than 1 for the increment.
(and another weird thing is that it wouldn't let me compare with the 0.15 without np.all() or np.any() on the delta_low_three). It throws an error about the truth ambiguity with numpy.
class Previous_Strong(CustomFactor):
inputs = [USEquityPricing.low] #USEquityPricing.high, USEquityPricing.close]
# outputs =
window_length = 22
mask = is_tradable_long
def compute(self, today, asset_id, out, low):
day = -1
while np.abs(day) < 20:
x = (low[day]+low[day-1]+low[day-2])/3
delta_low_three = low[day] - x
delta_low_three = np.abs(delta_low_three)
day -= 1
increment = 0
if np.abs(np.all(delta_low_three)) < 0.15:
increment += 1
out[:] = increment