Dear all
I am relatively new on Quantopian and looking for a custom factor / pipeline way to make a pipeline which would calculate and select out only equities with gaps (previous trading day's close to today's open) with specific threshold (e.g. selecting only gaps between 1% and 3% as of gap size/last day's close to normalize gaps and select out "biggish but not too much" gaps).
I read the pipeline tutorial and found a couple of examples. I am looking in something like that (below) but not sure it works. Obviously, one could achieve that without using pipeline but I believe that pipeline is more powerful tool.
Any help is very appreciated.
Snippet of a code
from quantopian.research import run_pipeline
from quantopian.pipeline.data import morningstar
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline import CustomFactor, Pipeline
import numpy as np
class Gap(CustomFactor):
"""
Computes the difference between close price of a previous trading date and
open price today.
"""
inputs = [USEquityPricing.close, USEquityPricing.open]
def compute(self, today, assets, out, close, open):
out[:] = open[0] - close[-1] # here I foresee some issues. Not sure it should be done like that
def make_pipeline():
yesterday_close = USEquityPricing.close
tradable_gaps = ((gap_pct > 1) & (gap_pct < 3)) # defining what range of gaps I am interested in (1-3% i.e. gap size normalized to close price)
return Pipeline(
columns={
'gap_pct': gap_pct,
},
screen=tradable_gaps
)
result = run_pipeline(make_pipeline(), '2015-05-05', '2015-05-05')
result.head()