Dow Jones Hidden Markov Model Analysis
A comprehensive project for analyzing Dow Jones financial time series data using Hidden Markov Models (HMM) and the Viterbi algorithm.
This project:
- Fetches historical Dow Jones (^DJI) data from 1995 to present
- Preprocesses and engineers financial features (returns, volatility, momentum)
- Builds a Hidden Markov Model with multiple hidden states
- Applies the Viterbi algorithm to decode the most likely hidden state sequence
- Visualizes results and analyzes market regimes
├── src/
│ ├── data_fetcher.py # Download Dow Jones data
│ ├── feature_engineering.py # Create financial features
│ ├── hmm_model.py # Hidden Markov Model implementation
│ ├── viterbi_algorithm.py # Viterbi algorithm for state decoding
│ └── visualization.py # Plotting and analysis
├── data/ # Downloaded data and results
├── main.py # Main execution script
├── requirements.txt # Project dependencies
└── README.md # This file
- Clone or download this project
- Create a virtual environment (optional but recommended):
python -m venv venv venv\Scripts\activate - Install dependencies:
pip install -r requirements.txt
Run the main analysis:
python main.py
This will:
- Download Dow Jones historical data
- Train the HMM model
- Run Viterbi algorithm
- Generate visualizations
- Save results to the
data/folder
Downloads historical Dow Jones data using yfinance library.
Calculates returns, volatility, momentum, and other technical indicators.
Hidden Markov Model
Implements HMM with:
- Multiple hidden states (representing market regimes: Bull, Normal, Bear)
- Gaussian emission probabilities
- Estimated transition and emission matrices
Decodes the most likely sequence of hidden states given the observed returns data.
The model identifies different market regimes and their transitions, helping to understand:
- Bull market states (high returns, low volatility)
- Normal market states (moderate returns)
- Bear market states (negative returns, high volatility)
- Python 3.7+
- See
requirements.txtfor dependencies