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.
-Importing KMeans from scikit learn python library
from sklearn.cluster import KMeans
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
Implementing KMeans for detecting clusters
f = ['mom', 'vol']
model = KMeans(n_clusters=4)
model.fit(data[f])
cluster = model.predict(data[f])