Project Overview
PatternPulse OS is a professional‑grade technical pattern recognition and research suite that fuses rule‑based geometric pattern detection with an optional PyTorch LSTM confidence filter. It identifies classical chart patterns—Head & Shoulders, Double Bottoms, Cup & Handle, and Symmetrical Triangles—using deterministic geometry (scipy.signal.argrelextrema) and validates them through walk‑forward backtesting.
The suite includes two Streamlit applications: a Live Scanner for real‑time pattern detection and a Historic Backtester for evaluating pattern performance across historical datasets. A Jupyter notebook provides detailed visualisations and performance metrics overlaid on price charts.
Problem Statement
Technical analysis relies on subjective visual interpretation of chart patterns, which is time‑consuming and prone to bias. While machine learning models can detect patterns automatically, they often lack explainability and can introduce overfitting. PatternPulse bridges this gap with a deterministic, rule‑based detection layer that is interpretable and testable, paired with an optional LSTM post‑detection filter that adjusts confidence scores without driving primary detection.
Architecture & Pattern Detection
All pattern detectors are rule‑based and deterministic, using scipy.signal.argrelextrema with configurable order and tolerance. They identify local extrema and apply geometric constraints to detect formations:
- Head & Shoulders: Three peaks (left shoulder, head, right shoulder) where head > shoulders, with neckline troughs, and confirms a breakout below the neckline.
- Double Bottom: Two troughs at similar price levels, an intermediate peak (neckline), and a breakout above it.
- Cup & Handle: Rounded bottom (cup) followed by a small consolidation (handle), with a breakout above the right rim.
- Symmetrical Triangle: Converging trendlines (lower highs and higher lows) with a breakout in either direction.
Each detector outputs a confidence score (0–1) based on geometric quality. The LSTM is used only as an optional post‑detection filter to adjust confidence scores; it does not drive primary detection.
Workflow (simplified): Price Data → Extrema Detection → Geometric Pattern Matching → Confidence Scoring → [Optional LSTM Filter] → Signal Output
Backtesting & Evaluation
The system uses walk‑forward validation (expanding window) to evaluate pattern performance, avoiding look‑ahead bias. For each pattern detected up to time t, it measures the forward return over a fixed horizon (e.g., 10 days) and computes:
- Win Rate: Fraction of patterns where price moved in the expected direction.
- Sharpe Ratio: Annualised return / standard deviation of strategy returns (assuming trading on each pattern signal).
- Maximum Drawdown: Largest peak‑to‑trough decline in cumulative strategy equity.
To assess the LSTM's added value, the system compares against baselines:
- Buy‑and‑Hold: Long the underlying asset throughout the period.
- SMA Crossover: A 50/200‑day Simple Moving Average strategy (classic trend‑following).
Note: The LSTM often does not significantly outperform the baselines; its main contribution is a marginal improvement in precision for certain patterns. This honest assessment is part of the research ethos.
Core Features
- Rule‑Based Geometry: Detects classic technical patterns using
scipy.signal.argrelextremaand geometric constraints (symmetry, slope, retracement). - Optional LSTM Confidence Filter: PyTorch LSTM trained on‑the‑fly to adjust confidence scores (post‑detection only).
- Walk‑Forward Validation: Expanding window backtesting avoids look‑ahead bias; reports Sharpe, max drawdown, win rate.
- Baseline Comparisons: Compares pattern signals against Buy‑and‑Hold and SMA crossover to assess added value.
- Unit Tests: Deterministic detectors covered by
pytestwith synthetic test cases. - Results Notebook: Jupyter notebook with example detections and performance metrics overlaid on price charts.
- Live & Historic Apps: Streamlit apps for real‑time scanning and historical backtesting.
Technology Stack
The core is written in Python, using PyTorch for LSTM confidence filtering, SciPy for extremum detection, and Pandas for data manipulation. The frontend uses Streamlit for interactive dashboards and Plotly for charting. Pattern detection algorithms are fully deterministic and covered by unit tests (pytest), ensuring reproducibility.
Results & Disclaimer
PatternPulse has been tested on multiple historical datasets. Key findings:
- Pattern Detection: Successfully identifies Head & Shoulders, Double Bottoms, Cup & Handle, and Symmetrical Triangles with high geometric fidelity.
- Backtesting: Walk‑forward validation provides realistic performance estimates, with results visualised in the Historic Scanner app.
- Unit Test Coverage: Deterministic detectors are thoroughly tested with synthetic price series.
⚠️ Disclaimer: This software is provided for research and educational purposes only. It does not constitute investment advice. Past performance does not guarantee future results. Always consult a qualified financial advisor before making investment decisions.
The project is structured as a modular research suite with live and historic scanning applications, making it suitable for quantitative researchers and developers interested in technical pattern analysis.