This project analyzes financial assets using a Hidden Markov Model (HMM) to identify different market regimes and patterns. The analysis includes calculating daily returns, rolling volatility, and volume changes, and visualizing the hidden states identified by the HMM.
- Fetches historical asset data using yfinance
- Calculates daily returns, rolling volatility, and volume changes
- Cleans the data by handling NaN and infinite values
- Standardizes the data using StandardScaler
- Fits a Gaussian HMM model with 4 hidden states
- Predicts hidden states and adds them to the original data
- Plots hidden states against asset prices for visualization
-
Clone the Repository:
git clone https://github.com/your-repo/hmm-based-asset-analysis.git cd hmm-based-asset-analysis
-
Install Dependencies:
pip install -r requirements.txt
To run the analysis, use the following command:
python hmmAlgo.py --ticker <TICKER_SYMBOL> --start_date <START_DATE> --end_date <END_DATE> --plotter <PLOTTER_TYPE>
Replace <TICKER_SYMBOL>
, <START_DATE>
, <END_DATE>
, and <PLOTTER_TYPE>
with appropriate values. For example:
python hmmAlgo.py --ticker AAPL --start_date 2020-01-01 --end_date 2021-01-01 --plotter line
After running the analysis, you will see visualizations of hidden states against asset prices.
This project is licensed under the MIT License. See the LICENSE file for details.
I would like to thank the contributors of the following libraries and tools that made this project possible: