This project explores the application of Hidden Markov Models (HMM) in developing a cryptocurrency trading strategy. Focusing on Bitcoin (BTC-USD), it utilizes historical data for model training and strategy testing.
Historical BTC-USD data is fetched from Yahoo Finance for the period from '2022-01-01' to '2023-12-31', including features like Open, High, Low, Adjusted Close, and Volume.
- Daily returns and price ranges are calculated.
- 12-day and 21-day moving averages are computed.
- The dataset is split into training and testing sets.
A Gaussian Hidden Markov Model with 4 components is trained on 'Returns' and 'Range', aimed at uncovering latent financial states for generating trading signals.
- Trading signals are generated based on Moving Average and HMM predictions.
- A combined signal integrates both MA and HMM for decision-making.
- Cumulative returns for both the benchmark (Bitcoin) and the strategy are calculated.
- The Sharpe Ratio, assessing risk-adjusted returns, is computed for both.
Returns Benchmark: Total percentage return of Bitcoin.Returns Strategy: Total percentage return of the strategy.Sharpe Benchmark: Risk-adjusted return of Bitcoin.Sharpe Strategy: Risk-adjusted return of the trading strategy.
This project demonstrates the integration of machine learning in financial trading, particularly using HMM for cryptocurrency trading strategies.
- Install Python packages:
pandas,numpy,hmmlearn,yfinance,matplotlib. - Execute the script to perform data fetching, model training, and strategy evaluation.
- Review the output for performance analysis.
- Data source: Yahoo Finance
- Libraries:
pandas,numpy,hmmlearn,yfinance,matplotlib
This project is licensed under the MIT License - see the LICENSE.md file for details.