Skip to content

Repository files navigation

PatternPulse OS

Technical Pattern Recognition & Research Suite
🌐 Live Scanner · 📊 Historic Backtester · 🐛 Report Bug · 💬 Discussions

Live Demo CI License Python Streamlit PyTorch SciPy

⚠️ 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.


📖 Table of Contents


✨ Features

Feature Description
📐 Rule‑Based Geometry Detects classic technical patterns using scipy.signal.argrelextrema and geometric constraints (symmetry, slope, retracement).
🧠 Optional LSTM Confidence Filter Optional 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 pytest with 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.

🧠 Pattern Detection Logic

All pattern detectors are rule‑based (deterministic) and use scipy.signal.argrelextrema with configurable order and tolerance. They identify local extrema and apply geometric constraints to detect formations. The LSTM is used only as an optional post‑detection filter to adjust confidence; it does not drive primary detection.

  • 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 and optional LSTM confirmation.

Workflow Diagram (simplified):

graph TD
    A[Price Data] --> B[Find Extrema]
    B --> C{Pattern Detector}
    C -->|Head & Shoulders| D[Geometric Constraints]
    C -->|Double Bottom| D
    C -->|Cup & Handle| D
    C -->|Symmetrical Triangle| D
    D --> E[Confidence Score]
    E --> F[Optional LSTM Filter]
    F --> G[Final Signal]
Loading

📊 Backtesting & Evaluation

We employ walk‑forward validation (expanding window) to evaluate pattern performance, avoiding look‑ahead bias. For each pattern detected up to time t, we measure the forward return over a fixed horizon (e.g., 10 days) and compute:

  • Win Rate: Fraction of patterns where price moved in the expected direction.
  • Sharpe Ratio: Annualized return / standard deviation of strategy returns (assuming trading on each pattern signal).
  • Maximum Drawdown: Largest peak‑to‑trough decline in cumulative strategy equity.

Baseline Comparisons

To assess the LSTM’s added value, we compare against:

  1. Buy‑and‑Hold – long the underlying asset throughout the period.
  2. Simple Moving Average Crossover – a 50/200‑day SMA strategy (classic trend‑following).

Results are displayed in the Historic Scanner app and can be exported. The LSTM often does not significantly outperform the baselines; its main contribution is a marginal improvement in precision for certain patterns, but it also introduces complexity and overfitting risk. This honest assessment is part of the research ethos.


🧪 Unit Tests

Deterministic pattern‑detection functions are covered by unit tests using pytest. Synthetic price series with known patterns are generated to verify correct identification. Run tests with:

pytest test_patterns.py -v

See test_patterns.py for details.


📓 Results Notebook

results_notebook.ipynb contains walk‑through examples of detected patterns overlaid on historical price charts, along with performance metrics and baseline comparisons. Open it with Jupyter or VS Code to explore.


🛠️ Setup

git clone https://github.com/yourusername/PatternPulse.git
cd PatternPulse
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt

Run the applications:

  • Live Scanner: streamlit run live_market.py
  • Historic Scanner: streamlit run historic_market.py
  • Landing Page: open landing.html in a browser

📁 Project Structure

PatternPulse/
├── live_market.py              # Real‑time scanning with optional LSTM
├── historic_market.py          # Local dataset backtesting & evaluation
├── landing.html                # Neutral gateway UI
├── stock_symbols.txt           # Default symbols
├── requirements.txt            # Dependencies
├── test_patterns.py            # Unit tests for pattern detection
├── results_notebook.ipynb     # Example visualisations
├── excels/                     # Historical datasets (XLSX)
└── README.md

📝 License

MIT License – see LICENSE for details.

Made with ❤️ by Your Name and contributors.

About

PatternPulse is a professional-grade technical analysis suite that fuses geometric pattern recognition (Head & Shoulders, Cup & Handle) with PyTorch LSTM deep learning for high‑confidence market signals.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages