How I Built a Quantitative Penny Stock Screener in Python
The Problem With Penny Stocks
Penny stocks are the Wild West of the financial markets. Priced under a dollar—and in many cases under fifteen cents—these micro-cap securities trade on OTC (Over-the-Counter) markets where regulatory oversight is thinner, information is scarcer, and the line between legitimate opportunity and outright fraud can blur in an instant.
The statistics are sobering: according to the SEC, a significant percentage of penny stocks eventually become worthless. Pump-and-dump schemes are endemic. Liquidity can evaporate overnight. And yet, the allure persists—because when a penny stock moves, it moves. A stock trading at $0.05 that hits $0.10 just delivered a 100% return.
The question isn't whether opportunities exist in penny stocks. They do. The question is: can you find them systematically, assess their risk quantitatively, and manage your exposure with discipline?
That's the question Penny was built to answer.
What is Penny?
Penny is an open-source Python CLI tool and web dashboard for screening, analyzing, backtesting, and simulating trades on OTC penny stocks priced under $0.15. It combines real-time market data from multiple API sources with a comprehensive suite of technical indicators, a multi-factor risk assessment engine, composite scoring, automated exit strategies, and a full campaign-based backtesting system—all wrapped in a React dashboard with Art Deco aesthetics.
The system is designed around a simple philosophy: treat penny stock trading as an engineering problem. Replace gut feelings with quantitative signals. Replace hope with exit strategies. Replace hindsight with backtesting.
Architecture Overview
Penny is built as a modular Python application with a React frontend, structured around a clear data pipeline:
- Data Ingestion — Multi-source market data from Polygon.io, Finnhub, and SEC EDGAR
- Universe Construction — Identify eligible OTC stocks meeting price and volume thresholds
- Technical Analysis — Calculate RSI, MACD, Bollinger Bands, breakout scores, and volume metrics
- Risk Assessment — Score pump-and-dump probability, delisting risk, and liquidity quality
- Composite Scoring — Weight all factors into a single actionable grade (A through F)
- Exit Strategy — Seven-priority signal system for disciplined position management
- Backtesting — Campaign-based historical simulation with parallel execution
The tech stack includes Python 3.11+ with Typer for the CLI, FastAPI for the web backend, React 19 with TypeScript for the dashboard, and SQLite for caching and state management. The whole system runs in Docker with automated backups to DigitalOcean Spaces.
Data Sources: Where the Numbers Come From
Penny pulls data from multiple sources, each serving a specific role:
Polygon.io is the primary data source. It provides the OTC stock universe, OHLCV (Open-High-Low-Close-Volume) candle data, real-time quotes, and news. Polygon's coverage of OTC markets is what makes Penny possible—most retail-oriented data providers simply don't cover the sub-penny space.
Finnhub serves as a fallback for quotes, news, and company profiles. With a 60-call-per-minute free tier, it provides redundancy when Polygon data is unavailable.
SEC EDGAR provides regulatory filing data via RSS feeds. SEC filings can be early signals of material events—reverse splits, delinquent filings, or change-of-control notices that often precede significant price moves.
All API responses are cached with intelligent TTLs: universe data for 24 hours, candle data for 15 minutes, company profiles for 7 days, and news for 1 hour. A thread-safe sliding-window rate limiter prevents API throttling, and a circuit breaker pattern handles API failures gracefully.
The Screening Pipeline
The screener begins by constructing its universe: up to 1,000 OTC tickers from Polygon, filtered to stocks priced at or below $0.15. From there, each stock must pass two volume gates:
- Minimum daily volume: 100,000 shares (ensures basic liquidity)
- Minimum Relative Volume (RVOL): 2.0x the 20-day average (ensures something is happening today)
Stocks that pass these gates enter the analysis pipeline, where 60 days of OHLCV data are analyzed across four dimensions.
Technical Indicators: Reading the Tape
Penny implements five core technical indicators, each contributing to a technical score from 0 to 100.
RSI (Relative Strength Index)
The RSI is a momentum oscillator that measures the speed and magnitude of recent price changes on a scale of 0 to 100. Penny uses the standard 14-period calculation.
- Below 30: Oversold territory—potential bounce candidate
- 50 to 70: Bullish sweet spot—momentum without overextension
- Above 70: Overbought—caution warranted, used as an exit signal
In penny stocks specifically, RSI tends to be more volatile than in large-caps, making the 50-70 range particularly valuable as a confirmation signal rather than a primary entry trigger.
MACD (Moving Average Convergence Divergence)
The MACD tracks the relationship between two exponential moving averages (12-period fast, 26-period slow) and a 9-period signal line. Penny tracks four states:
- Bullish crossover: MACD line crosses above signal line (buy signal)
- Bearish crossover: MACD line crosses below signal line (sell signal)
- Bullish: MACD above signal (uptrend confirmed)
- Bearish: MACD below signal (downtrend confirmed)
The implementation uses strict inequality—touching lines do not count as crossovers—reducing false signals in the noise-heavy penny stock environment.
Bollinger Bands
Bollinger Bands plot two standard deviations above and below a 20-period moving average, creating a dynamic envelope around price. Penny tracks:
- Band position: Where price sits within the bands (0 = lower band, 1 = upper band)
- Band width: How wide the bands are as a percentage of the middle band
- Squeeze detection: When band width drops below 10%, volatility compression is occurring—often a precursor to explosive moves
A Bollinger squeeze in a penny stock with rising RVOL is one of the most interesting setups the screener can identify.
Price vs. Moving Average
A straightforward but effective signal: is the current price above or below the 20-day moving average? Penny classifies this as:
- Above: Price is more than 2% above the MA (bullish)
- Below: Price is more than 2% below the MA (bearish)
- At: Price is within 2% of the MA (neutral)
Breakout Detection (Multi-Factor Score)
The breakout detector combines multiple signals into a single 0-100 score:
| Factor | Points | Signal |
|---|---|---|
| RVOL ≥ 2.0x | +25 | Volume surge |
| RSI > 50 | +20 | Bullish momentum |
| Price > 20-MA | +20 | Uptrend |
| Within 3% of resistance | +20 | Near breakout level |
| Price > 20-day high | +15 | Confirmed breakout |
A score of 60 or above flags the stock as a potential breakout. This multi-factor approach reduces false positives that plague single-indicator breakout systems.
Volume Analysis: Following the Smart Money
In penny stocks, volume is arguably the single most important indicator. Price can be manipulated with relatively small amounts of capital, but sustained volume patterns are harder to fake. Penny implements four volume metrics:
RVOL (Relative Volume)
Relative Volume compares today's volume to the 20-day average. It's the first filter in the screening pipeline and one of the most important signals:
- 2-5x: Significant—something is driving interest
- 5-10x: Major event—news, filing, or institutional activity
- 10x+: Extreme—could be opportunity or danger
OBV (On-Balance Volume)
On-Balance Volume is a cumulative indicator that adds volume on up days and subtracts it on down days. The trend of OBV over 10 periods reveals whether volume is flowing into (accumulation) or out of (distribution) a stock:
- Accumulation: OBV increased more than 10%—buyers are in control
- Distribution: OBV decreased more than 10%—sellers are in control
- Neutral: OBV within 10%—no clear direction
Volume Surge Detection
A dual-timeframe check comparing current volume against both the 20-day and 5-day averages. A stock can have high RVOL against the 20-day average but declining short-term volume—that's a fading move, not a fresh one.
Volume Score (0-100)
RVOL and OBV combine into a single volume score:
| Component | Condition | Points |
|---|---|---|
| RVOL | ≥ 10x | +50 |
| RVOL | ≥ 5x | +40 |
| RVOL | ≥ 2x | +25 |
| OBV | Accumulation | +50 |
| OBV | Neutral | +25 |
| OBV | Distribution | +0 |
Risk Assessment: The Guardian at the Gate
Technical analysis tells you what could go right. Risk assessment tells you what will go wrong if you're not careful. Penny's three-dimensional risk engine is arguably its most important feature.
Pump-and-Dump Detection
Pump-and-dump schemes are the plague of penny stock markets. Penny's detector scores six factors on a 0-10 scale:
| Factor | Condition | Points |
|---|---|---|
| Rapid price appreciation | +100% in 5 days | +3 |
| Rapid price appreciation | +50-100% in 5 days | +2 |
| Extreme volume | > 20x 20-day average | +3 |
| Extreme volume | > 10x 20-day average | +2 |
| Social media buzz | > 100 mentions | +2 |
| Parabolic move | > 50% 1-day AND > 5x volume | +2 |
| Known promotional campaign | Detected | +3 |
Risk levels map to recommendations: LOW (0-2) gets an OK, MEDIUM (3-4) gets CAUTION, HIGH (5-6) gets AVOID, and CRITICAL (7+) gets AVOID with emphasis. The screener can be configured to filter out any stocks above a chosen risk threshold.
Delisting Risk
Exchanges have minimum listing requirements, and penny stocks frequently skirt or violate them. Penny's delisting risk model evaluates:
- Price compliance: How long has the stock traded below $1? (30+ consecutive days = +4 points)
- Reverse split history: Has the company done reverse splits to maintain listing compliance? (+2 points)
- Extreme dilution: Cumulative split ratio above 250:1? (+3 points)
- Sub-penny territory: Price below $0.01? (+2 points)
A stock with a CRITICAL delisting risk score (6+) is essentially a ticking clock—it may still trade, but the structural risk of total loss is extreme.
Liquidity Analysis
The bid-ask spread is the hidden cost of trading penny stocks. A stock might look profitable on a chart, but if the spread is 20%, you're starting every trade in a deep hole. Penny categorizes spreads as:
- Excellent: < 2%
- Good: 2-5%
- Fair: 5-10%
- Poor: 10-20%
- Very Poor: 20%+
Stocks with spreads above 10% are flagged as unacceptable for trading.
Composite Scoring: One Number to Rule Them All
All the individual analyses feed into a weighted composite score:
Composite = (Technical Score x 0.40)
+ (Volume Score x 0.25)
+ (Risk Score x 0.25)
+ (Sentiment Score x 0.10)The risk score is inverted (100 minus risk x 10) so that higher composite scores always mean better opportunities. The result maps to letter grades:
| Grade | Score Range | Interpretation |
|---|---|---|
| A | 80-100 | Strong Buy Signal |
| B | 65-79 | Buy Signal |
| C | 50-64 | Neutral |
| D | 35-49 | Caution |
| F | 0-34 | Avoid |
Sentiment analysis contributes only 10% of the composite—deliberately low because news sentiment for penny stocks is noisy and often manipulated. The system uses keyword-based scoring across 47 positive and 27 negative keywords extracted from aggregated news feeds.
The Exit Strategy System: Seven Ways to Get Out
Ask any experienced trader and they'll tell you: entries are easy, exits are everything. Penny implements a seven-priority exit signal system, evaluated in strict priority order. The first triggered signal wins.
Priority 1: Technical Confirmation
RSI above 70 and MACD bearish crossover. Both conditions must be true simultaneously. This is the classic "momentum exhaustion" signal—the stock has run out of steam by multiple measures.
Priority 2: Trailing Stop
Price has dropped 20% from the highest price since entry. This is the core risk management tool—it lets winners run while protecting against catastrophic reversal. The trailing stop ratchets up as price increases and never moves down.
Priority 3: Volume Spike Sell-off
Volume exceeds 4x the 5-day average and price drops more than 5% in the session. This pattern—massive volume combined with a sharp price decline—often signals institutional or large-holder distribution.
Priority 4: Support Break
Price falls below the 20-day low. When a stock breaks below its recent trading range on the downside, it often accelerates. This exit prevents small losses from becoming big ones.
Priority 5: Profit Targets
Two-tiered target system:
- 30% gain: Full position exit (take the win)
- 20% gain: Partial exit of 50% (lock in profits, let the rest ride)
Priority 6: Stagnant Position
If a position has been held for 10+ days with less than 5% gain, it's consuming capital that could be deployed elsewhere. This is the "opportunity cost" exit.
Priority 7: ATR Stop
Price falls below entry minus 2.5x the Average True Range (ATR). ATR measures volatility, so this stop adapts to each stock's natural price movement—tight stops for calm stocks, wider stops for volatile ones.
Backtesting: Proving It Works (or Doesn't)
Penny's backtesting engine doesn't just check whether the screener would have found good stocks—it simulates the entire trading lifecycle including entries, exit strategy evaluation, and portfolio management.
How It Works
A backtest campaign selects a date range and frequency (daily, weekly, or monthly). For each date:
- Universe reconstruction: What OTC stocks existed and were trading on that date?
- Historical screening: Apply the same filters and scoring using only data available at that time (no look-ahead bias)
- Forward returns: Track what happened to screened stocks over 1, 5, 20, and 60 days
- Exit simulation: Simulate the full position lifecycle using historical price data and exit strategy rules
Exit Strategy Presets
The backtester offers three presets to test different risk/reward profiles:
| Parameter | Conservative | Moderate | Aggressive |
|---|---|---|---|
| Fixed Stop-Loss | 8% | 10% | 15% |
| Trailing Stop | 15% | 20% | 25% |
| Profit Target | 20% | 30% | 50% |
| Max Hold Period | 30 days | 60 days | 90 days |
| Stagnant Exit | 7 days / 3% | 10 days / 5% | 15 days / 10% |
| RSI Threshold | 65 | 70 | 75 |
Performance
The backtesting system is heavily optimized for performance:
- Parallel execution across configurable worker threads
- SQLite-backed cache with ~95% hit rate after initial data fetch
- Batch API calls using Polygon's grouped bars endpoint
- Cross-population: a single API call can populate cache entries for hundreds of symbols
- Negative caching to eliminate redundant database queries
- LRU cache (512 entries) for grouped bar lookups
A weekly campaign over one year runs in about 5-8 minutes with cached data. A daily campaign takes 30-60 minutes.
The Dashboard: Art Deco Meets Data Science
The Penny dashboard is built with React 19, TypeScript, Recharts, and Radix UI, wrapped in an Art Deco visual theme that makes data analysis genuinely enjoyable.
Key dashboard views include:
- Campaign Overview: High-level metrics across all backtest dates
- Day Navigator: Step through individual backtest dates to examine picks and outcomes
- Equity Curve: Visualize portfolio value over time
- Win Rate Over Time: Track how screening accuracy trends across dates
- Returns Distribution: Histogram of individual trade returns
- Exit Reason Breakdown: Pie chart showing which exit signals fire most often
- Investment Simulator: Configure starting capital, per-stock allocation, and commission percentage to model real-world portfolio growth
- Backtest Manager: Launch new campaigns directly from the UI
The Investment Simulator deserves special mention. It takes the raw backtest results and models what would have happened with actual capital—accounting for position sizing, commissions, and the compounding effect of reinvesting gains. Default settings: $1,000 starting capital, $25 per position, 1% commission.
Testing and Security
Penny has 448 passing tests covering unit tests, integration tests, performance benchmarks, and security validations. Performance benchmarks verify that RSI calculation completes in under 1ms, cache lookups in under 10ms, and JSON serialization for 100 stocks in under 100ms.
Security tests validate API key protection, SQL injection prevention, path traversal defense, XSS protection, and input symbol validation. In a system that handles financial data and makes network requests, these aren't optional extras.
Infrastructure
Penny runs in Docker with automated daily backups to DigitalOcean Spaces. Backups use gzip compression and WAL (Write-Ahead Logging) checkpointing for SQLite database integrity. A 7-day retention policy keeps storage manageable while providing adequate recovery window.
Lessons From Building a Penny Stock Screener
Building Penny reinforced several principles that apply to any quantitative trading system:
- Risk management is more important than stock selection. The exit strategy system exists because even the best screener will pick losers. The goal isn't to be right every time—it's to cut losers quickly and let winners run.
- Volume doesn't lie (usually). In micro-cap markets where a single large order can move the price 20%, sustained volume patterns are the most reliable signal. Price can be painted; volume is harder to fake at scale.
- Backtesting without exit simulation is fantasy. Forward returns (what happened 5 days later?) are interesting but misleading. What matters is what happened during the holding period with realistic entry and exit rules.
- Data quality is the foundation. The evolution from FMP to Polygon as the primary data source wasn't a preference—it was a necessity. OTC market data has gaps, inconsistencies, and sometimes outright errors. Multi-source validation and intelligent caching are essential.
- The best trade is often no trade. Penny's risk engine exists to say "no." The pump-and-dump detector, the delisting risk assessor, and the liquidity analyzer all serve as gatekeepers. A screener that only identifies opportunities without quantifying risk is a recipe for disaster.
Further Reading
If you're interested in penny stock analysis or quantitative trading, these resources are worth exploring:
- SEC Guide to Microcap Stocks — Essential reading on the risks and realities of penny stock investing
- Investopedia: Penny Stocks — Comprehensive overview of penny stock characteristics and risks
- Relative Strength Index (RSI) — Deep dive into the momentum oscillator Penny relies on
- MACD Indicator — Understanding the moving average convergence divergence
- Bollinger Bands — John Bollinger's volatility envelope technique
- On-Balance Volume (OBV) — Joe Granville's volume-momentum indicator
- Average True Range (ATR) — Welles Wilder's volatility measure used in Penny's exit strategy
- FINRA: Penny Stock Risks — The regulator's perspective on penny stock dangers
- Polygon.io API Documentation — The primary data source powering Penny's analysis
- OTC Markets Group — The marketplace where penny stocks trade
Disclaimer
Penny is a screening and analysis tool, not financial advice. Penny stocks carry extreme risk—a significant percentage are eventually delisted and become worthless. Never invest money you cannot afford to lose. Always do your own research before investing. Past performance, including backtest results, is not indicative of future returns.