feat: implement Volatility Hunter for real-time market scanning #25

Merged
jihoson merged 1 commits from feature/issue-20-volatility-hunter into main 2026-02-04 16:32:31 +09:00
Collaborator

Summary

Implements issue #20 - Behavioral Rule: Volatility Hunter

This PR adds a real-time market scanning system that continuously identifies the fastest-moving stocks across all markets and dynamically updates watchlists to focus on market leaders.

Components Implemented

1. Volatility Analysis (src/analysis/volatility.py)

  • VolatilityAnalyzer class with comprehensive technical analysis:
    • ATR (Average True Range) calculation for volatility measurement
    • Multi-timeframe price change tracking (1m, 5m, 15m intervals)
    • Volume surge detection (ratio vs average)
    • Price-volume divergence analysis (bullish/bearish signals)
    • Combined momentum scoring (0-100 scale)
    • Breakout/breakdown pattern detection with volume confirmation

2. Market Scanner (src/analysis/scanner.py)

  • MarketScanner class for real-time market monitoring:
    • Scans ALL available stocks every 60 seconds
    • Ranks stocks by momentum score
    • Identifies top 5 movers per market
    • Detects breakout/breakdown patterns
    • Dynamic watchlist management (replaces laggards with leaders)
    • Stores scan results in Context Tree L7 (real-time layer)

3. Main Loop Integration (src/main.py)

  • Integrated scanner into trading loop
  • Auto-adjusts WATCHLISTS dynamically based on market leaders
  • Replaces up to 2 lagging stocks per scan cycle
  • Requires volume confirmation for watchlist changes
  • Full Context Tree L7 integration for real-time data storage

4. Comprehensive Testing (tests/test_volatility.py)

  • 22 comprehensive tests covering:
    • All volatility calculation methods
    • Scanner ranking and market scanning
    • Watchlist update logic
    • Breakout/breakdown detection
    • Error handling and edge cases
  • 99% code coverage for analysis module
  • All 103 tests passing

Key Features

  • Leader Detection: Automatically identifies stocks with highest momentum
  • Volume Confirmation: All breakouts require volume surge (2x minimum)
  • Multi-Timeframe Analysis: Considers 1m, 5m, and 15m price changes
  • Dynamic Watchlists: Replaces lagging stocks with market leaders
  • Context Tree Integration: Stores volatility data in L7 real-time layer
  • Breakout Detection: Identifies price breakouts/breakdowns with volume

Technical Details

  • ATR Period: 14 periods (standard)
  • Minimum Volume Surge: 2.0x average
  • Minimum Price Change: 1.0% for breakouts
  • Scan Interval: 60 seconds
  • Top Movers: 5 per market
  • Max Replacements: 2 per scan cycle

Test Results

============================= 103 passed in 4.82s ==============================

Coverage:
- src/analysis/scanner.py:     100%
- src/analysis/volatility.py:   98%
- Overall analysis module:      99%

Linting

ruff check src/analysis/ tests/test_volatility.py
All checks passed!

Impact

This implementation enables The Ouroboros to:

  1. React faster to market opportunities by scanning all stocks
  2. Focus resources on the most volatile, high-momentum stocks
  3. Adapt dynamically as market conditions change
  4. Avoid laggards by continuously replacing weak performers
  5. Confirm signals using both price and volume analysis

Test Plan

  • All unit tests pass (103/103)
  • Coverage ≥80% (99% achieved)
  • Ruff linting passes
  • No type errors in new code
  • Integration with main trading loop
  • Context Tree L7 storage working
  • Watchlist updates working correctly

Generated with Claude Code

## Summary Implements issue #20 - Behavioral Rule: Volatility Hunter This PR adds a real-time market scanning system that continuously identifies the fastest-moving stocks across all markets and dynamically updates watchlists to focus on market leaders. ## Components Implemented ### 1. Volatility Analysis (`src/analysis/volatility.py`) - **VolatilityAnalyzer** class with comprehensive technical analysis: - ATR (Average True Range) calculation for volatility measurement - Multi-timeframe price change tracking (1m, 5m, 15m intervals) - Volume surge detection (ratio vs average) - Price-volume divergence analysis (bullish/bearish signals) - Combined momentum scoring (0-100 scale) - Breakout/breakdown pattern detection with volume confirmation ### 2. Market Scanner (`src/analysis/scanner.py`) - **MarketScanner** class for real-time market monitoring: - Scans ALL available stocks every 60 seconds - Ranks stocks by momentum score - Identifies top 5 movers per market - Detects breakout/breakdown patterns - Dynamic watchlist management (replaces laggards with leaders) - Stores scan results in Context Tree L7 (real-time layer) ### 3. Main Loop Integration (`src/main.py`) - Integrated scanner into trading loop - Auto-adjusts WATCHLISTS dynamically based on market leaders - Replaces up to 2 lagging stocks per scan cycle - Requires volume confirmation for watchlist changes - Full Context Tree L7 integration for real-time data storage ### 4. Comprehensive Testing (`tests/test_volatility.py`) - 22 comprehensive tests covering: - All volatility calculation methods - Scanner ranking and market scanning - Watchlist update logic - Breakout/breakdown detection - Error handling and edge cases - **99% code coverage** for analysis module - All 103 tests passing ## Key Features - **Leader Detection**: Automatically identifies stocks with highest momentum - **Volume Confirmation**: All breakouts require volume surge (2x minimum) - **Multi-Timeframe Analysis**: Considers 1m, 5m, and 15m price changes - **Dynamic Watchlists**: Replaces lagging stocks with market leaders - **Context Tree Integration**: Stores volatility data in L7 real-time layer - **Breakout Detection**: Identifies price breakouts/breakdowns with volume ## Technical Details - **ATR Period**: 14 periods (standard) - **Minimum Volume Surge**: 2.0x average - **Minimum Price Change**: 1.0% for breakouts - **Scan Interval**: 60 seconds - **Top Movers**: 5 per market - **Max Replacements**: 2 per scan cycle ## Test Results ``` ============================= 103 passed in 4.82s ============================== Coverage: - src/analysis/scanner.py: 100% - src/analysis/volatility.py: 98% - Overall analysis module: 99% ``` ## Linting ``` ruff check src/analysis/ tests/test_volatility.py All checks passed! ``` ## Impact This implementation enables The Ouroboros to: 1. **React faster** to market opportunities by scanning all stocks 2. **Focus resources** on the most volatile, high-momentum stocks 3. **Adapt dynamically** as market conditions change 4. **Avoid laggards** by continuously replacing weak performers 5. **Confirm signals** using both price and volume analysis ## Test Plan - [x] All unit tests pass (103/103) - [x] Coverage ≥80% (99% achieved) - [x] Ruff linting passes - [x] No type errors in new code - [x] Integration with main trading loop - [x] Context Tree L7 storage working - [x] Watchlist updates working correctly Generated with Claude Code
agentson added 1 commit 2026-02-04 16:30:48 +09:00
feat: implement Volatility Hunter for real-time market scanning
Some checks failed
CI / test (pull_request) Has been cancelled
62b1a1f37a
Implements issue #20 - Behavioral Rule: Volatility Hunter

Components:
1. src/analysis/volatility.py
   - VolatilityAnalyzer with ATR calculation
   - Price change tracking (1m, 5m, 15m intervals)
   - Volume surge detection (ratio vs average)
   - Price-volume divergence analysis
   - Momentum scoring (0-100 scale)
   - Breakout/breakdown detection

2. src/analysis/scanner.py
   - MarketScanner for real-time stock scanning
   - Scans all available stocks every 60 seconds
   - Ranks by momentum score
   - Identifies top 5 movers per market
   - Dynamic watchlist updates

3. Integration with src/main.py
   - Auto-adjust WATCHLISTS dynamically
   - Replace laggards with leaders (max 2 per scan)
   - Volume confirmation required
   - Integrated with Context Tree L7 (real-time layer)

4. Comprehensive tests
   - 22 tests in tests/test_volatility.py
   - 99% coverage for analysis module
   - Tests for all volatility calculations
   - Tests for scanner ranking and watchlist updates
   - All tests passing

Key Features:
- Scan ALL stocks, not just current watchlist
- Dynamic watchlist that adapts to market leaders
- Context Tree integration for real-time data storage
- Breakout detection with volume confirmation
- Multi-timeframe momentum analysis

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
jihoson merged commit ad1f17bb56 into main 2026-02-04 16:32:31 +09:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jihoson/The-Ouroboros#25