Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/s1dewalker/markov-model-for-stocks
Building Markov Model for Stocks after applying Clustering to Time Series data
https://github.com/s1dewalker/markov-model-for-stocks
clustering kmeans-clustering machine-learning markov-decision-process markov-model pandas probabilistic-models python sklearn stochastic-processes time-series
Last synced: 12 days ago
JSON representation
Building Markov Model for Stocks after applying Clustering to Time Series data
- Host: GitHub
- URL: https://github.com/s1dewalker/markov-model-for-stocks
- Owner: s1dewalker
- Created: 2025-01-22T20:17:24.000Z (15 days ago)
- Default Branch: main
- Last Pushed: 2025-01-22T20:53:21.000Z (15 days ago)
- Last Synced: 2025-01-22T21:24:24.533Z (15 days ago)
- Topics: clustering, kmeans-clustering, machine-learning, markov-decision-process, markov-model, pandas, probabilistic-models, python, sklearn, stochastic-processes, time-series
- Language: Jupyter Notebook
- Homepage:
- Size: 685 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Markov-Model-for-Stocks
Building Markov Model for Stocks after applying Clustering to Time Series data in Python
## 1. Applying k-means clustering to identify market states
1. Data Preparation
2. Feature Preparation
3. **Check for Multicollinearity**
4. **Normalize** (as some features might dominate due to larger scale) w/ `MinMaxScaler`
5. **Finding Optimal k** w/ WCSS or **elbow method**
6. Perform Silhouette analysis for different k
7. Fit the model and identify the clusters
8. Analyzing clusters
9. Analyzing each cluster
**Finding Optimal k with elbow method**
![]()
**Pairwise Feature Relationships by Cluster**
#### [View Clustering](https://github.com/s1dewalker/Markov-Model-for-Stocks/blob/main/py_files/MarkovModel1_Clustering.ipynb)
Python libraries used: `pandas`, `yfinance`, `sklearn`, `matplotlib`, `seaborn`
## 2. Building Markov Model to create a Transition matrix
1. Get previous state
2. Create Transition State by combining previous and present states
3. Grouping by Transition state and Counting their occurrences
4. Separate the transition state
5. Create Markov transition matrix
6. Convert to row-wise percentages (%)
#### [View Model](https://github.com/s1dewalker/Markov-Model-for-Stocks/blob/main/py_files/MarkovModel2-Building_MarkovModel.ipynb)
Python libraries used: `pandas`