Skip to content
All projects
Tools & Dashboards

Nifty 500 Beta Clustering Dashboard

nifty-beta-clustering

A Streamlit app that downloads price history for the NSE master universe plus the Nifty 50 index, computes each stock's beta via OLS regression of stock returns against market returns, scales features, and runs KMeans to cluster stocks into beta regimes — Negative, Low, Market and High Beta — rendered with Plotly.

This repo previously also contained five unrelated bolted-on apps; it has been trimmed back to just this original dashboard, with the others split into properly-named repositories of their own.

Verified correct

Beta computed via proper OLS (not confused with the intercept), return date-alignment via index intersection, and StandardScaler-before-KMeans — confirmed by a synthetic test with known leveraged series, where exact 1.5× and −0.8× copies recovered beta = 1.5 and −0.8 exactly, plus live runs against real data.

Fixed in review

  • Cluster labels were assigned purely by rank position from a fixed lookup table, not from the cluster's actual data. Reproduced live with a 15-stock run where the cluster labeled "Negative Beta" contained only stocks with positive beta (0.46–0.72). Fixed by labeling each cluster from its own real mean beta against fixed thresholds.
  • A hardcoded default end date already five months stale at time of review.
  • An unguarded yf.download() call that crashed the whole app on a network hiccup, even though a friendly error path already existed right next to it and was simply never wired up.
  • A hardcoded "333 NSE stocks" caption that could drift from the real universe size.
  • The repo had no README before the review; one now documents the app, the fixes, and the caveats — beta instability over lookback windows, heuristic cluster count and thresholds, not investment advice.
KMeansOLS betaPlotlyStreamlit
Next projectnifty-dcf-valuation-dashboard