Market Data & Web Scraping
Beginner
Scan Stocks for High Relative Volume (RVOL > 2x) & Gap-Up Breakouts in Python
Identify stocks in play by computing Relative Volume (Current Volume vs 20-Day Average Volume) and Overnight Gap Percentage in Python Pandas.
#pandas#numpy
Problem Statement
Intraday momentum setups fail when a stock lacks institutional participation. Filtering for Relative Volume (RVOL >= 2.0) combined with an Opening Gap (>1.5%) isolates the highest-momentum stocks of the day.
Formula / Core Logic
RVOL = Volume_t / SMA(Volume, 20)_{t-1}
Gap_Pct = 100 * (Open_t - Close_{t-1}) / Close_{t-1}
Installation
pip install pandas numpy
relative-volume-rvol-gap-up-premarket-scanner-python.py
import pandas as pd
import numpy as np
def scan_rvol_and_gaps(df, vol_window=20, min_rvol=2.0, min_gap_pct=1.5):
df = df.copy()
avg_vol = df['Volume'].rolling(vol_window).mean().shift(1)
df['RVOL'] = (df['Volume'] / avg_vol).round(2)
df['Gap_Pct'] = (((df['Open'] - df['Close'].shift(1)) / df['Close'].shift(1)) * 100).round(2)
df['Stock_In_Play'] = np.where((df['RVOL'] >= min_rvol) & (df['Gap_Pct'].abs() >= min_gap_pct), 1, 0)
return df
Get the Complete 100+ Python Quant & Automation Bundle
Instant lifetime access to all production-ready scripts, valuation models, and trading bots ($19).
Buy Full Bundle on Gumroad ($19) →Frequently Asked Questions
Q: Why shift the 20-day average volume by 1 bar?
Excluding today's volumespike from the baseline average ensures an accurate comparison against normal historical volume.