Building Markov Model for Stocks after applying Clustering to Time Series data in Python
- Data Preparation
- Feature Preparation
- Check for Multicollinearity
- Normalize (as some features might dominate due to larger scale) w/
MinMaxScaler
- Finding Optimal k w/ WCSS or elbow method
- Perform Silhouette analysis for different k
- Fit the model and identify the clusters
- Analyzing clusters
- Analyzing each cluster
Finding Optimal k with elbow method
Pairwise Feature Relationships by Cluster
Python libraries used: pandas
, yfinance
, sklearn
, matplotlib
, seaborn
- Get previous state
- Create Transition State by combining previous and present states
- Grouping by Transition state and Counting their occurrences
- Separate the transition state
- Create Markov transition matrix
- Convert to row-wise percentages (%)
Python libraries used: pandas