/Exploratory-data-analysis-and-Regime-Detection-using-KMean--Nifty-50

Performing EDA on Indian indices and Kmeans to detect market regimes

Primary LanguageJupyter Notebook

Exploratory data analysis and Regime Detection using KMean- Nifty-50

The goal of this project is to look at the NIFTY-50 data as well as the sectoral indices and visualise them in order to acquire useful information. Also, use the scikit learn python library's Kmean (unsupervised learning model) to find regimes.

Exploratory data analysis

  • Visualization market performance 2019 onwards using plotly python library

App Screenshot

  • Major single day fall

App Screenshot

  • Major single day gain

App Screenshot

  • Box plot - Closing price of different indices

App Screenshot

Regime Detection - Using unsupervised learning algorithm

Use of Regime Detection in finance

  • To determine which trading model or trading strategy to execute at any particular time, we use regime detection.

-Importing KMeans from scikit learn python library

from sklearn.cluster import KMeans
  • Creating Volatility and Momemtum feature
window = 20
data['mom'] = data[symbol].rolling(window).mean()
data['vol'] = data[symbol].rolling(window).std()
  • Scale the dataset to improve the model's performance
data = (data - data.mean())/data.std()
  • Scatter plot of Momemtum vs Volatility App Screenshot

  • Implementing KMeans for detecting clusters

f = ['mom', 'vol']
model = KMeans(n_clusters=4)
model.fit(data[f])
cluster = model.predict(data[f])
  • Plotting cluster detected by KMeans model

App Screenshot

Regime detected by the model

  • Positive Momentum and low Volatility
  • Positive Momentum and high Volatility
  • Negative Momentum and high volatility
  • Negative Momentum and low volatility