Hi Community,
I'm trying to implement a Gap-Trading-Algorithm, where the logic is quite simple: Buy, when the Close of the previous day is higher than n% compared to Open today.
For that I've defined the following custom factor:
class CloseOpenGap(CustomFactor):
#defaults
inputs = [USEquityPricing.close, USEquityPricing.open]
window_length = 2
def compute(self, today, asset_ids, out, close, open):
out[:] = ( open[0] / close[-1] ) - 1
The screen-filter is pretty simple:
gap_minus_5 = (gap < context.LONG_THRESHOLD)
However, the results are confusing. I'm buying on Market Open
schedule_function(my_market_open, date_rules.every_day(), time_rules.market_open())
but the price is sowhat different to the expected gap price.
My questions:
- Is the CustomFactor compute is right to calc the gap between yesterday.close and todays.open? (
out[:] = ( open[0] / close[-1] ) - 1
) refers the index 0 to the current day in the pipeline? I can't find any docs - Is there any difference between USEquityPricing and the historical prices in Yahoo? I've tried to match the them, but there are slightly different - so I'm a bit confused
Thank you for your help!
best regards,
Peter