Skip to content

A Crypto trading algorithm using a Hidden Markov Model to identify market regimes, execute trades, and backtest against a HODL baseline, complete with an interactive performance dashboard.

License

Notifications You must be signed in to change notification settings

Yosri-Ben-Halima/hmm-crypto-trading-model

Repository files navigation

Hidden Markov Model (HMM) Bitcoin Trading Strategy

A quantitative trading framework that applies Hidden Markov Models (HMMs) to Bitcoin.
The goal is to identify hidden market regimes (e.g., bullish or bearish) and adapt trading decisions accordingly — instead of passively holding Bitcoin.


Overview

This project combines statistical modeling, machine learning, and backtesting to evaluate whether regime-switching strategies can outperform a simple Buy & Hold (HODL) benchmark.

The pipeline includes:

  • Data loading and feature engineering
  • State calibration and HMM training
  • Signal generation based on inferred regimes
  • Backtesting with transaction costs
  • Benchmarking against Buy & Hold
  • Monte Carlo simulations for robustness

Average Results (Monte-Carlo on Test Period)

Metric HMM Strategy Buy & Hold
Annualized Sharpe 1.71 1.02
P&L (%) +51% +23%
Max Drawdown (%) -21% -28%

Over Jan-Aug 2025 backtest period, the HMM strategy delivered higher risk-adjusted returns, while reducing drawdowns compared to simply holding Bitcoin.


Quick Start

Clone the repo and install dependencies:

git clone https://github.com/Yosri-Ben-Halima/hmm-crypto-trading-model.git
cd hmm-crypto-trading-model
pip install -r requirements.txt

Run the Jupyter notebook for a full example:

jupyter notebook main.ipynb

⚠️ Disclaimer

This project is for educational and research purposes only. It is not investment advice and should not be used for live trading.


Connect with Me

Thank you for visiting my GitHub profile! Feel free to reach out if you have any questions or opportunities to collaborate. Let's connect and explore new possibilities together:

GitHub LinkedIn Facebook Instagram Email Personal Web Page Google Drive PyPI

About

A Crypto trading algorithm using a Hidden Markov Model to identify market regimes, execute trades, and backtest against a HODL baseline, complete with an interactive performance dashboard.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •