CoolFace
Apppublic

Figure31/pattern-finder

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
README.md111 linesDownload Raw Back to root
1---2title: BTC Pattern Finder3emoji: ๐Ÿ“Š4colorFrom: blue5colorTo: yellow6sdk: streamlit7sdk_version: 1.27.08app_file: app.py9pinned: false10---11 12# BTC Pattern Finder13 14A tool to discover similar historical patterns in Bitcoin price movements.15 16## Overview17 18BTC Pattern Finder analyzes Bitcoin price data to find historical patterns that match specified timeframes. It uses the Matrix Profile algorithm (via the STUMPY library) to identify the most similar price shapes across Bitcoin's history.19 20## Features21 22- Search for patterns across multiple timeframes (1m, 3m, 5m, 15m, 30m, 1h, 4h, 1d, 1w)23- Visualize matches with what happened after each pattern24- Compare current price movements with historical patterns25- Rank matches by similarity score26- View detailed price data for each match27- Access real BTC price data from Binance API (back to 2017)28 29## Installation30 311. Clone the repository:32```bash33git clone <repository-url>34cd btc_pattern_finder35```36 372. Create a virtual environment:38```bash39python -m venv venv40source venv/bin/activate  # On Windows: venv\Scripts\activate41```42 433. Install dependencies:44```bash45pip install -r requirements.txt46```47 48 49## Usage50 511. Start the Streamlit application:52```bash53streamlit run app.py54```55 562. The app will open in your browser (default: http://localhost:8501)57 583. Interact with the application:59   - Select a timeframe (1m to 1w)60   - Choose recent data or specify a date range61   - Select a pattern on the chart62   - Adjust pattern length and other parameters63   - Click "Find Similar Patterns"64 65## How It Works66 67The pattern matching uses a technique called Matrix Profile (implemented by the STUMPY library). It works by:68 691. Z-normalizing the price data (removing mean and scaling by standard deviation)702. Computing sliding window comparisons between your selected pattern and historical data713. Ranking matches by a distance score (lower means more similar patterns)724. Filtering out duplicate matches that are too close in time73 74The z-normalization means we're matching the **shape** of the pattern rather than absolute price levels.75 76 77### Data Source78 79The system uses Binance API to fetch BTCUSDT spot market data:80- Historical data available back to 2017 (Binance's launch)81- Support for timeframes from 1m to 1w82- Automatically handles long time periods by chunking requests83- No API key required for historical data access84 85## Project Structure86 87- `app.py` - Streamlit web interface88- `btc_pattern_finder.py` - Core pattern matching logic89- `data_provider.py` - Binance API data provider implementation90- `data_cache.py` - Local caching to minimize API calls  91- `visualization.py` - Pattern visualization utilities92 93## Future Enhancements94 95- Probabilistic price direction forecasting96- Real-time pattern detection97- Multiple asset comparison98 99## Requirements100 101- Python 3.8+102- STUMPY (for pattern matching)103- Pandas & NumPy (for data handling)104- Plotly (for visualization)105- Streamlit (for web interface)106 107## Notes108 109- The application uses Binance's public API to fetch real BTCUSDT spot market data110- For minute-level timeframes, data is available back to 2017111- No API key is required for accessing historical price data