Skip to content

datainbloom/BTC-Dip-Detector-ML

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

36 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ’ธ Dip Detector ML ๐Ÿšจ

Welcome to the BTC Dip Detector project! This machine learning repository is built to detect significant dips in Bitcoin prices using historical data, statistical indicators, and classification models. This project is being developed as part of The Knowledge House 2025 Data Science Fellowship.


Dip Detector ML Flowchart
This diagram shows how DipDetectorML fetches live Bitcoin data, checks for price dips, runs a machine learning forecast, and then delivers alerts and dashboard updates to the user


Team Name: Wave Riders ๐ŸŒŠ
Team Members:

  • Jessenia (Lead)
  • Kachi
  • Mohammed
  • Rosania
  • Belkis

DipDetectorML is a hybrid system that combines:

  1. โšก Rule-based live alerts โ€“ monitors Bitcoin (BTC) in real time and emails users when dips of 2%, 5%, 10%, 15%, or 20% occur.
  2. ๐Ÿค– Machine learning forecasting โ€“ trains a Random Forest model on historical BTC data to predict the probability of a โ‰ฅ20% monthly dip and sends a monthly warning email if risk is high.

Itโ€™s designed for long-term Bitcoin accumulators who never sellโ€”only buy โ€œas mucho and as often as possible.โ€ By layering real-time alerts with predictive foresight, DipDetectorML helps users supercharge their Dollar Cost Averaging (DCA) strategy, stacking more BTC at better prices.


๐ŸŽฏ Motivation

Bitcoin is one of the most volatile assets in modern finance:

  • ๐Ÿ“‰ Daily or weekly dips of ~10โ€“20% can occur during volatile periods.
  • ๐Ÿ“Š Even in bull markets, ~20โ€“27% corrections are common โ€œhealthy pullbacks.โ€
  • ๐Ÿ“… In Feb 2025, BTC saw a ~17% monthly drop.
  • ๐Ÿป Full bear markets can bring 50โ€“80% drawdowns.

Static buy orders in exchange apps are tied to fixed prices, quickly go stale as BTC trends, and provide no foresight.
DipDetectorML is different: alerts are percentage-based (adaptive at any price) and we also provide a predictive monthly risk signal. Itโ€™s built for accumulators who DCA steadily but size up on deep dips and plan liquidity ahead of downturns.

This project is also a real-world ML case study:

  • ๐Ÿงน Data collection/cleaning from crypto APIs
  • ๐Ÿ› ๏ธ Feature engineering (returns, volatility, RSI-14, log (volume))
  • ๐Ÿง  Model training with class imbalance
  • ๐Ÿ“ฌ Deployment: live polling, CSV logging, multi-recipient email

๐Ÿ“˜ Project Overview

End-to-end system for monitoring and predicting BTC dips:

  1. Live dip alerts

    • Polls CoinGecko /coins/markets every 60s
    • Checks 24h & 7d % changes vs thresholds (2/5/10/15/20)
    • Appends each sample to data/live_btc_log.csv (proof + charts)
    • Emails all subscribers whose preferences match the dip
  2. Historical training + ML forecast

    • Pulls daily OHLC + volume via /market_chart
    • Features: 1/3/7-day returns, rolling vol (7/14d), RSI-14, log(volume)
    • Trains RandomForestClassifier to predict a โ‰ฅ20% next-month dip risk
    • Saves model to models/rf_monthly.pkl
    • Runs monthly to send one โ€œhigh-riskโ€ forecast email

๐Ÿ‘ฅ Users

Primary users are:

  • Retail crypto investors and long-term accumulators.
  • Students and analysts learning applied machine learning on financial time-series.
  • Educators and instructors reviewing our project for technical rigor.

They want:

  • ๐Ÿ“ง Clear, reliable email alerts.
  • ๐Ÿ“Š Simple visuals and dashboards.
  • ๐Ÿ”ฎ Actionable insights (probabilities, not just thresholds).

โš™๏ธ Setup Instructions

Clone the repo and set up dependencies:

git clone https://github.com/your-username/DipDetectorML.git
cd DipDetectorML

python3 -m venv .venv
source .venv/bin/activate   # Mac/Linux
.\.venv\Scripts\activate    # Windows

pip install -r requirements.txt

๐Ÿ—‚๏ธ Code Structure

BTC-DipDetector-ML/
โ”‚
โ”œโ”€โ”€ Data/
โ”‚   โ””โ”€โ”€ bitcoin_cleaned_with_features.csv
โ”‚
โ”œโ”€โ”€ files/
โ”‚   โ”œโ”€โ”€ dip_detector_model.pkl
โ”‚   โ”œโ”€โ”€ feature_list.pkl
โ”‚   โ””โ”€โ”€ monthly_forecast.py
โ”‚
โ”œโ”€โ”€ Images/
โ”‚   โ””โ”€โ”€ DipDetectorML_Architectural_Flowchart.png
โ”‚
โ”œโ”€โ”€ Notebooks/
โ”‚   โ”œโ”€โ”€ Belkis.ipynb
โ”‚   โ”œโ”€โ”€ Jessenia.ipynb
โ”‚   โ”œโ”€โ”€ ML_Random_Forest_Mohammed.ipynb
โ”‚   โ”œโ”€โ”€ Onyekachi.ipynb
โ”‚   โ””โ”€โ”€ Rosania.ipynb
โ”‚
โ”œโ”€โ”€ DipDetectorML_FlowChart.md
โ”œโ”€โ”€ DipDetectorMLapp.py
โ”œโ”€โ”€ core.py
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ .env


๐Ÿ“‘ Data Sources

Live BTC prices: CoinGecko API ๐ŸฆŽ

Historical CSV: cached from CoinGeckoโ€™s /market_chart endpoint

Model outputs: /data/ml_monthly_prob.json


๐Ÿงช Testing Data

Weโ€™ll build a 20-example test set covering:

Easy: clear 20% dips (label = 1).

Medium: borderline dips (10โ€“19% changes).

Hard: false positives (volatile days that recover).

Out-of-scope: sideways markets with no significant dips.

Correctness defined by: modelโ€™s probability alignment with true label (โ‰ฅ0.5 = dip, else no dip), plus evaluation on AUC and precision/recall.


๐Ÿ›  ๐Ÿ“ฆ Dependencies and Tools

Key libraries used in this project:

pandas, numpy โ†’ data wrangling

requests โ†’ API calls (CoinGecko)

scikit-learn, joblib โ†’ ML (Random Forest)

matplotlib, seaborn, plotly โ†’ visualization

streamlit โ†’ dashboard demo

boto3, python-dotenv โ†’ (future SES integration)

See requirements.txt for full list.

Scikit-learn: Logistic Regression, Random Forest (main ML).

XGBoost / LightGBM: optional boosted-tree experiments.

(Stretch) TensorFlow/Keras for LSTM.

Requests / Pandas: API ingestion and data wrangling.

Matplotlib / Seaborn: visualization.

SMTP integration: alerts/notifications.


๐Ÿ“Š Metrics (Mohammedโ€™s Outputs)

The Random Forest classifier was trained on BTC daily OHLC + features like lagged returns, RSI, and volatility.

AUC: 0.74

Precision: 0.68

Recall: 0.55

Confusion Matrix + Classification Report: included in /reports/metrics.txt.

Example test row outputs include:

Date

Engineered features

Predicted probability

Actual next-day return

Label (dip / no dip)


โœ… Results & Evaluation (MVP Checkpoint)

Working Prototype

  • Live alerts: System polls CoinGecko and triggers emails on threshold breach. (For demo we temporarily set a tiny threshold, e.g., โˆ’0.1%, to force an alert and prove delivery.)
  • Random Forest model: Trains on cached CSV of historical BTC features; outputs a probability of a โ‰ฅ20% monthly dip.

Evaluation

  • Notebook includes 10โ€“20 test rows with: date, engineered features, predicted probability, actual next-day return, and label (dip/no dip).
  • Report AUC and precision/recall at the chosen probability cutoff.
  • Include confusion matrix and classification report (Mohammedโ€™s code).

Current Status of Email

  • SMTP wiring is in progress (Kachi). Alerts trigger correctly; configuring credentials/routes for reliable inbox delivery is the remaining step.

๐Ÿ’ก Value Proposition

DipDetectorML is a smarter accumulation assistant for long-term holders:

Provides immediate situational awareness (rule-based alerts).

Adds predictive foresight for portfolio risk management (ML monthly forecast).

Educationally, demonstrates both classical ML (Random Forest, Logistic Regression) and time-series approaches (possible LSTM as a stretch goal).

  • ๐Ÿ”„ Better than static buy orders: static limit prices go stale; percent-based alerts adapt at any price level.
  • ๐Ÿงญ Control + discipline: we notify; you decide sizing. Example rule-set:
    • 5% dip โ†’ advance weekly DCA
    • 10% dip โ†’ 2ร— DCA
    • 20% dip โ†’ 3ร— DCA
  • ๐Ÿ”ฎ Predictive foresight: the monthly crash forecast helps you stage cash ahead of major downturns rather than reacting late.

๐Ÿ“Š BTC Dip Alerts - Live & ML Dashboard

โš ๏ธ Limitations

  • โš–๏ธ Class imbalance: true โ‰ฅ20% dips are rare; requires careful thresholding and metrics.
  • โณ Non-stationarity: crypto regimes change; models can drift.
  • ๐Ÿ”’ API rate limits: CoinGecko free tier is 100k requests/month โ†’ poll responsibly.
  • ๐ŸŽฏ Scope: MVP focuses on BTC; multi-asset remains future work.
  • ๐Ÿ“ง Email delivery: SMTP configuration still being finalized.

โœ… Solutions to Risks

Address imbalance with class_weight="balanced" in Random Forest/LogReg.

Consider expanding dataset to include multiple coins (ETH, XRP) for training, even if evaluation is BTC-only.

Keep LSTM/GRU as a stretch goal; Random Forest = main deliverable.

Allow flexible thresholds for rule-based alerts to balance alert frequency.


๐Ÿ”ฎ Future Work

  • ๐Ÿ“ˆ Backtests: compare DCA-only vs DCA + DipDetectorML over 1โ€“3 years (extra BTC stacked).
  • ๐ŸŒ Add ETH, XRP, and others; cross-asset signals.
  • ๐Ÿ“ฐ Add news/sentiment features (Fed/CPI, ETF flows, exchange events).
  • ๐Ÿš€ Model upgrades: XGBoost/LightGBM; sequence models (LSTM/GRU).
  • ๐Ÿ“ฒ Slack bot or mobile push as alternatives to email.
  • ๐Ÿ‘ฅ User preferences: per-user tiers, unsubscribe links, dashboards.
  • โ˜๏ธ AWS SES + DynamoDB for production alerts.

๐Ÿ™ Acknowledgments & Team Contributions

๐Ÿ‘ฅ Team Contributions

  • Jessenia (Lead): ๐ŸŒŸ Slack + GitHub setup, README, standups, documentation, demo coordination, final submission.
  • Onyekachi: โšก Built live API polling + dip logic, CSV logging; actively integrating SMTP for email delivery.
  • Mohammed: ๐Ÿค– Implemented RandomForestClassifier, engineered features, ran Grid/RandomizedSearchCV, produced AUC/precision/recall, confusion matrix, and saved the model with joblib.
  • Rosania: ๐Ÿ“ Drafted documentation and background research.
  • Belkis: โœ‰๏ธ Email intergration collaboration.

๐Ÿ™Œ Special Acknowledgments

  • Maurice (Mentor) ๐Ÿ’ก โ€” for constructive guidance, review, and unwavering support throughout the project.
  • Farukh (Instructor) ๐ŸŽ“ โ€” for technical instruction, ML insight and insightful feedback.
  • Gaurav (Instructor) ๐ŸŽ“ โ€” for teaching, feedback, and continued assistance.

Special thanks also to CoinGecko ๐ŸฆŽ for providing free API access that made the live alert system possible.


๐Ÿ“œ License

MIT License.
CoinGecko API data subject to their terms of service: https://www.coingecko.com/en/terms

About

Dip Detector ML

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors