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.
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
| 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.
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.txtRun the Jupyter notebook for a full example:
jupyter notebook main.ipynbThis project is for educational and research purposes only. It is not investment advice and should not be used for live trading.
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: