We perform a K-means clustering for nifty50 stocks with an aim to diversify a portfolio with these bluechip stocks
Please note: This is not meant to be investment advice. Only for educational purposes
K-Means Clustering performed on Nifty50 stocks on the basis of price action from past 10 years
The following steps were followed:
1. Using YFinance python package the information for the nifty50 tickers were extracted.
2. New DataFrame created with daily close price, Annual returns and annual variance
3. Inertia is calculated and based on elbow method number of clusters are calculated as 4
4. We then fit the KMeans algorithm and get the cluster labels
5. A function is built to extract the stock with most returns in each cluster