<jupyter_start><jupyter_text>Disclaimer  Interactive Strategy DevelopmentBefore moving to a backtest, we can stay in a notebook a little longer and develop our code for identifying gaps. To start with, we import and re-run our pipeline from the previous notebook:<jupyter_code>from codeload.sell_gap.pipeline import make_pipeline
from zipline.research import run_pipeline

pipeline = make_pipeline()
candidates = run_pipeline(pipeline, start_date="2020-01-01", end_date="2020-08-15")<jupyter_output><empty_output><jupyter_text>Then we select a particular day to look at in more detail:<jupyter_code>candidates = candidates.xs("2020-08-13")<jupyter_output><empty_output><jupyter_text>And we load the corresponding data object as of 9:31 that day:> Note that in Zipline, bars contain data from the previous minute. The 9:31 bar contains the 09:30:00-09:30:59 OHLCV data. Thus, this bar contains the day's opening price.<jupyter_code>from zipline.research import get_data
data = get_data("2020-08-13 09:31:00")<jupyter_output><empty_output><jupyter_text>We are looking for gaps where the opening price is at least 1 standard deviation below the prior day's low and is also below the 20-day moving average. Using the pipeline output and the data object, we identify the gaps:<jupyter_code>today_opens = data.current(candidates.index, 'open')
prior_lows = candidates["prior_low"]
stds = candidates["std"]

# find stocks that opened sufficiently below the prior day's low...
gapped_down = today_opens < (prior_lows - stds)

# ...and are now below their moving averages
are_below_mavg = (today_opens < candidates["mavg"])

assets_to_short = candidates[
    gapped_down
    & are_below_mavg
    ]

print(assets_to_short)<jupyter_output>mavg  prior_low       std
Equity(FIBBG000C3J3C9 [CSCO])  47.0665      47.27  1.127427<jupyter_text>On this particular day, CSCO gapped down. We can check the opening price and validate it against other sources to make sure our logic was correct:<jupyter_code>print(today_opens[assets_to_short.index])<jupyter_output>Equity(FIBBG000C3J3C9 [CSCO])    43.79
Name: open, dtype: float64
{'fraction_non_alphanumeric': 0.0815552394499763, 'fraction_numerical': 0.044570886676149835, 'mean_word_length': 5.895424836601308, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '484551', 'license': 'Apache-2.0', 'n_tokens_mistral': 743, 'n_tokens_neox': 669, 'n_words': 218, 'path': 'sell_gap/Part3-Interactive-Strategy-Development.ipynb', 'repo_name': 'quantrocket-codeload/sell-gap', 'size': '2109'}