Skip to content

imanslab/Leveraging-Random-Forest-Algorithms-for-Enhanced-Bitcoin-Price-Forecasting-2024-Halving

Repository files navigation

Leveraging Random Forest Algorithms for Enhanced Bitcoin Price Forecasting 2024 Halving

This project employs advanced Random Forest algorithms to analyse and predict Bitcoin price movements, utilising comprehensive historical Bitcoin market data. The system focuses on critical market aspects including volatility patterns, market cycles, technical indicators (RSI, moving averages), and the impact of Bitcoin halving events. A significant research element is the 2024 Bitcoin halving event and its historical impact on Bitcoin's valuation trajectory.

Features and Benefits

Core Capabilities

  • Random Forest Algorithm: Implements ensemble learning with GridSearchCV hyperparameter optimisation for robust predictive modelling
  • Halving Events Analysis: Analyses Bitcoin halving events as significant market indicators and cyclical patterns
  • Comprehensive Data Analysis: Incorporates volatility metrics, market cycles, technical indicators, and historical price patterns
  • Time Series Cross-Validation: Uses TimeSeriesSplit for proper temporal validation avoiding data leakage

Advanced Visualisation Features

  • Enhanced Plot Visualisation: 24x12 inch high-resolution plots with dark theme optimised for analysis
  • Automated High/Low Detection: Intelligent identification and labelling of significant price extrema using signal processing
  • Monthly Time Markers: Granular monthly labels (Dec 2024 - Dec 2025) with weekly minor gridlines
  • Multi-Year Projections: Extended forecast period covering 13 months of future predictions
  • Color-Coded Annotations:
    • RED markers (▲) for price highs with formatted price labels
    • GREEN markers (▼) for price lows with formatted price labels
    • Current price annotation with directional arrow
  • Dual Prediction Display: Shows both estimated future top prices and Random Forest model predictions
  • Smart Label Positioning: Automatically positioned annotations to minimise overlap and maximise readability

Methodology

The methodology employs Random Forest algorithm to analyse historical Bitcoin data, focusing on periods around Bitcoin halving events to predict future price movements. The system uses:

  1. Feature Engineering: Creates lagged features and rolling statistics to capture temporal patterns
  2. Technical Indicators: Incorporates RSI, moving averages, and volatility metrics
  3. Time Series Validation: Uses TimeSeriesSplit to respect temporal ordering and prevent look-ahead bias
  4. Hyperparameter Optimisation: GridSearchCV explores 81 parameter combinations across 5 time-series folds (405 total model fits)
  5. Ensemble Prediction: Random Forest aggregates predictions from multiple decision trees for robust forecasting

⚠️ DISCLAIMER AND LEGAL NOTICE

PLEASE READ THIS ENTIRE SECTION CAREFULLY BEFORE USING THIS SOFTWARE

Educational and Research Purpose Only

This project is developed EXCLUSIVELY for educational, academic, and research purposes. It represents a self-study project exploring machine learning applications in financial time series analysis and should be treated as such.

Not Financial, Investment, or Trading Advice

CRITICAL NOTICE: The predictions, forecasts, analyses, visualisations, and any outputs generated by this software are NOT:

  • Financial advice
  • Investment recommendations
  • Trading signals or strategies
  • Professional investment counsel
  • Solicitations to buy, sell, or hold any financial instruments
  • Guarantees or promises of future performance
  • Substitutes for professional financial planning

High-Risk Asset Warning

Cryptocurrency Investments Carry Extreme Risk:

  • Bitcoin and cryptocurrencies are highly volatile and speculative assets
  • You can lose all invested capital - potentially 100% loss
  • Past performance does NOT indicate or guarantee future results
  • Cryptocurrency markets operate 24/7 with no circuit breakers or trading halts
  • Regulatory status varies by jurisdiction and may change unexpectedly
  • Market manipulation, fraud, and technical failures are documented risks
  • Liquidity can vanish instantly during market stress

Model Limitations and Accuracy

No Guarantees of Accuracy:

  • Machine learning models are inherently probabilistic and subject to error
  • Historical patterns may not repeat in future market conditions
  • Models cannot predict black swan events, regulatory changes, or unprecedented market conditions
  • The model's R² score and RMSE metrics reflect past performance only
  • Overfitting is possible despite cross-validation techniques
  • External factors (regulation, macro-economics, geopolitical events) are not captured by the model
  • Technical indicators (RSI, moving averages) are lagging indicators and may provide false signals

No Liability or Responsibility

Complete Disclaimer of Liability:

  • The author, contributors, maintainers, and affiliated parties accept ZERO responsibility for:
    • Any financial losses, damages, or opportunity costs incurred
    • Trading decisions made based on this software's outputs
    • Technical failures, bugs, or errors in the code
    • Data inaccuracies or corruption
    • Misinterpretation of results or visualisations
    • Regulatory or tax consequences of cryptocurrency activities

Use At Your Own Risk

By using this software, you explicitly acknowledge and agree that:

  • You are using this software entirely at your own risk
  • You will NOT make financial decisions solely based on this software
  • You understand the highly speculative nature of cryptocurrency investments
  • You are capable of bearing complete financial loss of any invested amounts
  • You have the technical knowledge to understand the code's limitations

Professional Advice Requirement

Mandatory Professional Consultation:

  • ALWAYS consult licensed financial advisers, accountants, and legal professionals before making investment decisions
  • Conduct independent research from multiple reputable sources
  • Verify all data and assumptions independently
  • Understand your personal risk tolerance and financial situation
  • Consider tax implications in your jurisdiction
  • Ensure decisions align with your long-term financial goals

Legal and Regulatory Compliance

User Responsibilities:

  • Ensure compliance with all applicable laws and regulations in your jurisdiction
  • Cryptocurrency trading and ownership may be restricted or prohibited in certain countries
  • Tax reporting requirements vary by jurisdiction - consult a tax professional
  • Anti-money laundering (AML) and know-your-customer (KYC) regulations may apply
  • Securities laws may classify certain cryptocurrencies as securities
  • The author provides no legal advice regarding compliance

Software "AS IS" Provision

No Warranties:

  • This software is provided "AS IS" without warranties of any kind, either express or implied
  • No warranty of merchantability, fitness for a particular purpose, or non-infringement
  • No guarantee of error-free operation, accuracy, reliability, or availability
  • The author reserves the right to modify or discontinue the project at any time without notice

Data Sources and Accuracy

Data Quality Disclaimer:

  • Historical data is sourced from third-party providers and may contain errors
  • The author does not guarantee data accuracy, completeness, or timeliness
  • Missing data, gaps, or outliers may affect model performance
  • Data preprocessing decisions involve subjective choices that impact results

Version Control and Updates

No Obligation to Update:

  • This software may become outdated as markets, technologies, and methodologies evolve
  • The author has no obligation to provide updates, bug fixes, or support
  • Newer versions may produce different results due to methodology changes
  • Users must independently verify the suitability of any version for their purposes

Prohibited Uses

This Software Must NOT Be Used For:

  • Making investment decisions without independent professional advice
  • Automated trading systems without thorough testing and risk management
  • Financial services requiring regulatory licences
  • Advising others on cryptocurrency investments
  • Any purpose that violates applicable laws or regulations

Acknowledgment of Understanding

By downloading, cloning, or using this software, you certify that:

  • You have read and understood this entire disclaimer
  • You accept all risks associated with cryptocurrency investment
  • You will not hold the author or contributors liable for any losses
  • You will use this software only for educational and research purposes
  • You will seek professional financial advice before making investment decisions
  • You understand that machine learning predictions are not certainties

Contact and Questions

If you do not agree with any part of this disclaimer, you must immediately cease using this software and delete all copies.


Technical Specifications

Model Architecture

  • Algorithm: Random Forest Regressor with ensemble learning
  • Hyperparameter Optimisation: GridSearchCV with TimeSeriesSplit (5-fold)
  • Feature Engineering:
    • Lagged features: 1, 3, 7, 14, 30 days
    • Rolling statistics: 7, 14, 30-day windows (mean, standard deviation)
    • Technical indicators: RSI, moving averages, volatility
    • Volume analysis
  • Feature Scaling: StandardScaler for normalisation
  • Validation: Time series cross-validation to prevent data leakage

Visualisation Technologies

  • Matplotlib: High-resolution plotting with dark theme
  • SciPy: Signal processing for extrema detection (argrelextrema)
  • Pandas: Time series data manipulation
  • NumPy: Numerical computations

Key Dependencies

  • Python 3.11+
  • scikit-learn 1.8.0+
  • TensorFlow (CPU optimised)
  • pandas
  • numpy
  • matplotlib
  • scipy
  • Node.js (for Dukascopy data download)

Prerequisites

  • Python 3.11 or higher
  • Git
  • Node.js and npm (for data collection)

Installation

Setting Up a Virtual Environment

First, create and activate a virtual environment:

python -m venv .venv  # Create a virtual environment
source .venv/bin/activate  # Activate on macOS and Linux
.venv\Scripts\activate  # Activate on Windows

Installing Dependencies

Install the required dependencies:

pip install -r requirements.txt  # Install Python dependencies
npm install dukascopy-node --save  # Install Node.js dependencies

Data Collection

chmod +x data-download.sh
./data-download.sh

Quick Start

Windows Specific Notes

  • Use PowerShell or Git Bash for shell commands.
  • Ensure Docker Desktop for Windows is set to Linux containers.
  • Python commands may require using py instead of python or python3.

Clone the Repository

To get started, clone the repository:

git clone git@github.com:imanslab/Leveraging-Random-Forest-Algorithms-for-Enhanced-Bitcoin-Price-Forecasting-2024-Halving.git

Usage

Running the Model

Execute the main.py script to start the data processing and model training/prediction process:

python main.py

What to Expect

The script will:

  1. Load or Train Model: If a saved model exists, it will be loaded; otherwise, GridSearchCV will train a new model (this may take 10-15 minutes)
  2. Generate Predictions: Produce predictions from December 2024 through December 2025
  3. Display Visualisation: Show an interactive plot with:
    • Historical actual Bitcoin prices (cyan line)
    • Estimated future top prices with HIGH/LOW labels (orange dashed line)
    • Random Forest predictions (magenta line with markers)
    • Monthly time markers for easy date reference
    • Automatically detected price extrema with annotations
    • Current price indicator
  4. Print Metrics: Display model evaluation metrics (RMSE and R²)

Understanding the Plot

  • RED Triangles (▲): Indicate predicted HIGH price points
  • GREEN Triangles (▼): Indicate predicted LOW price points
  • Orange Dashed Line: Shows estimated future top prices based on volatility analysis
  • Magenta Solid Line: Shows Random Forest model predictions
  • Monthly Grid: Major gridlines mark each month from Dec 2024 to Dec 2025
  • Price Labels: Formatted in thousands (K) or millions (M) for readability

Model Retraining

To retrain the model with new data or different parameters:

rm -rf model/random_forest_model.pkl
python main.py

This will trigger a fresh GridSearchCV run with the following parameter grid:

  • n_estimators: [100, 200, 300]
  • max_depth: [10, 20, 30]
  • min_samples_split: [2, 4, 6]
  • max_features: ['sqrt', 'log2', None]

Support and Subscribe

Contributing

Contributions to improve the project are welcome. Please adhere to standard open-source contribution guidelines.

Citation

If you use this project in your research or in any project, please cite it using the following:

Samizadeh, Iman. (2024). Leveraging Random Forest Algorithms for Enhanced Bitcoin Price Forecasting 2024 Halving. Version 1.0. [Online]. Available: https://github.com/imanslab/Leveraging-Random-Forest-Algorithms-for-Enhanced-Bitcoin-Price-Forecasting-2024-Halving and https://www.researchgate.net/publication/377591197_Leveraging_Random_Forest_Algorithms_for_Enhanced_Bitcoin_Price_Forecasting_2024_Halving

     @misc{Samizadeh2024BitcoinRF,
        author = {Samizadeh, Iman},
        title = {{Leveraging Random Forest Algorithms for Enhanced Bitcoin Price Forecasting 2024 Halving}},
        year = {2024},
        howpublished = {\url{https://github.com/imanslab/Leveraging-Random-Forest-Algorithms-for-Enhanced-Bitcoin-Price-Forecasting-2024-Halving}}
    }

Credit: https://github.com/Leo4815162342/dukascopy-node

About

The methodology employs Random Forest algorithm to analyze historical Bitcoin data, focusing on periods around Bitcoin halving events to predict future price movements.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors