Regime Detection in Bitcoin Using Hidden Markov Models (HMM) and Alpha-Stable Distributions
This repository demonstrates how to detect regime changes in financial markets, specifically Bitcoin, using Hidden Markov Models (HMM) with non-Gaussian Alpha-Stable distributions. The project uses the pomegranate library, which supports non-Gaussian distributions like Alpha-Stable, making it ideal for modeling Bitcoin’s highly volatile and non-normal return distribution.
- Hidden Markov Models (HMM): A statistical model where the system being modeled is assumed to follow a Markov process with hidden states.
- Alpha-Stable Distributions: Flexible distributions capable of modeling fat tails and asymmetry in financial data, unlike Gaussian distributions.
- Regime Detection: The identification of different market conditions (e.g., bull, bear, and range markets) and their transitions over time.
- Simulated Bitcoin Data: Simulates market conditions with bull, bear, and range markets, each with varying volatility levels.
- Alpha-Stable HMM: Uses Hidden Markov Models with Alpha-Stable distributions to model the returns.
- Regime Prediction: Detects market regimes based on the modeled data.
- Visualization: Visualizes the identified regimes on the time series data.
- CSV Export: Exports the time series and corresponding regimes to a CSV file for further analysis.
To run this project locally, follow these steps:
-
Clone the repository:
git clone https://github.com/your-username/regime-detection-bitcoin-hmm.git
-
Navigate to the project directory:
cd regime-detection-bitcoin-hmm
-
Install the required dependencies: This project uses the following libraries:
pomegranate
for HMM modelingnumpy
,pandas
for data manipulationmatplotlib
for visualization
Install them using the following command:
pip install -r requirements.txt
Run the notebook hmm_regime_detection.ipynb
, which simulates Bitcoin-like returns for 6 different market regimes (bull/bear/range with low/high volatility).
Step 2: Fit Hidden Markov Model
The notebook fits a Hidden Markov Model using pomegranate with Alpha-Stable distributions, making it ideal for modeling Bitcoin’s returns. It detects the underlying regimes in the simulated time series data.
The predicted regimes are visualized alongside the simulated returns, with each regime (market condition) highlighted using different colors.
The results (time series with predicted regimes) are exported as a CSV file for further analysis.
The core logic is implemented in the Jupyter notebook hmm_regime_detection.ipynb
. Here’s a brief breakdown:
- Simulates market regimes using numpy.
- Trains an HMM with pomegranate using Alpha-Stable distributions.
- Predicts the hidden states (regimes) and visualizes them using matplotlib.
- Exports the results to
regimes_prediction.csv
.