Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Gap screen should be returning no results, but it does

I am checking for stocks that have gapped up 100% (just to see the gap filter in play). The code used is attached. Unless there are some super edge cases, there should be no results. But that's not the case and the results that show don't show any sign of gapping when I check their daily charts. Any help?

The eventual goal is to screen for stocks that have gapped up 5% or higher the previous day.

2 responses

A couple of issues. First, the only filter on the pipeline is

filter_not_nan = signed_gap_pct.notnan()  
pipe.set_screen(filter_not_nan)

The reason the pipeline is returning a lot of stocks is there are a lot of stocks where your custom factor is 'not NaN'. I believe you want your screen to be something like this.

signed_gap_pct = SignedGapPct(mask=base_universe)  
pipe.set_screen(signed_gap_pct.eq(True))

Another small problem is with the custom factor. This line

 out[:] = ((open[-1] - close[-2])  / close[-2]) > 100

Should be

 out[:] = ((open[-1] - close[-2])  / close[-2]) > 1.0

The value will be greater than 1.0 if it's 100% (not 100).

That did it Dan, thanks. I was aware about the percentage goof, I was just placing random values as I thought it was the source of my problem.