Diversified Stock Portfolio Using Clustering Analysis
Abstract
This study constructs diversified equity portfolios from an S&P 500 panel by clustering stocks in a risk–return feature space and then selecting high-Sharpe names inside each cluster. The design separates two decisions that a global Sharpe screen conflates: which statistical neighbourhood a stock belongs to, and which names inside that neighbourhood have the best in-sample reward-to-risk.
Features are estimated only on the first 70% of the price history. K-means (, chosen by the elbow in within-cluster sum of squares) partitions the z-scored feature matrix. Two equal-weight books are then held fixed through the last 30% of the sample: a cluster-constrained 20-name portfolio (top five Sharpe names from each cluster) and an unconstrained top-20 Sharpe portfolio. Both are compared with the S&P 500 on holdout cumulative wealth.
The exercise is a portfolio-construction diagnostic, not a live trading system. Transaction costs, point-in-time index membership, and capacity are not modelled.
Sample Split and Feature Definitions
Daily prices for S&P 500 constituents and the index are aligned on a common calendar. Let be the length of that panel. The estimation window is ; the holdout is . No holdout return enters a feature, a cluster label, or a ranking.
For stock , daily simple returns are . With usable days in the training window and trading days per year, annualised return and volatility are
The training Sharpe used for ranking (excess return is not subtracted; the ratio is return over volatility) is . Market beta and price correlation versus the index return are
Two path-shape features capture typical intraday range: annualised mean open-to-close change and annualised mean high-to-low variation, each scaled by . Names with fewer than 60 overlapping training days are dropped.
Standardisation and the Choice of K
The feature vector is . Because these coordinates have incompatible units, each column is z-scored on the cross-section before clustering:
K-means minimises within-cluster sum of squares. For a candidate and partition with centroids ,
is read from the elbow of . On this panel the curve flattens at ****, which is the specification used for portfolio construction. The feature table and elbow chart below are computed on the training window only.
What this shows: Within-cluster sum of squares (WSS) by candidate cluster count K.
How to read it: Look for the elbow where WSS improvement starts flattening; that point suggests a practical K before diminishing returns.
Return vs volatility (K = 4). Color is cluster; hover for ticker.
Feature correlation matrix
| ann_return | ann_vol | ann_sharpe… | ann_daily_… | ann_daily_… | beta | cor | |
|---|---|---|---|---|---|---|---|
| ann_return | 1.000 | -0.234 | 0.946 | -0.731 | -0.233 | -0.153 | 0.674 |
| ann_vol | -0.234 | 1.000 | -0.286 | 0.355 | 0.975 | 0.839 | -0.178 |
| ann_sharpe… | 0.946 | -0.286 | 1.000 | -0.703 | -0.269 | -0.201 | 0.688 |
| ann_daily_… | -0.731 | 0.355 | -0.703 | 1.000 | 0.396 | 0.190 | -0.639 |
| ann_daily_… | -0.233 | 0.975 | -0.269 | 0.396 | 1.000 | 0.786 | -0.188 |
| beta | -0.153 | 0.839 | -0.201 | 0.190 | 0.786 | 1.000 | 0.118 |
| cor | 0.674 | -0.178 | 0.688 | -0.639 | -0.188 | 0.118 | 1.000 |
K-Means Partition
Lloyd’s algorithm is run on the z-scored matrix with , random initialisations, and a fixed seed so the labels are reproducible. Each name is assigned to the nearest centroid in Euclidean feature space. The objective is not to recover GICS sectors; it is to group stocks that look alike on return, volatility, beta, and path shape.
A global top-Sharpe screen can load the book with one corner of that space (for example, a cluster of low-beta compounders). Forcing representation from every centroid is a hard diversification constraint in feature space, analogous to a sector cap but defined by estimated risk characteristics rather than industry labels.
| Cluster | Count | Return | Vol | Sharpe | Beta |
|---|---|---|---|---|---|
| 1 | 71 | 11.200% | 24.400% | 0.476 | 0.619 |
| 2 | 19 | -19.300% | 54.600% | -0.378 | 1.610 |
| 3 | 43 | 16.300% | 37.800% | 0.419 | 1.266 |
| 4 | 60 | -6.600% | 30.400% | -0.215 | 0.757 |
Mean return
Mean volatility
Mean Sharpe
Two Construction Rules
Both books are long-only and equal-weighted, and weights are chosen once from training ranks — they are not re-estimated inside the holdout.
Cluster-constrained book. Inside each cluster , rank by training Sharpe and keep the top five names. With four clusters this is a 20-stock portfolio,
Unconstrained book. Rank the full cross-section by and hold the top 20 names at , with no cluster constraint. The difference in holdout paths is then attributable to the constraint, not to a different weighting scheme or a different universe.
By cluster: top 5 by Sharpe in each of 4 clusters (equal weight). Top 20: top 20 stocks by Sharpe overall.
Portfolio by cluster
CAH, COR, BSX, AJG, ACGL, FSLR, CCL, COIN, DASH, AMD, FICO, CEG, AVGO, AXON, APH, COP, CF, CHRW, SCHW, CDW
Top 20 by Sharpe
CAH, FICO, CEG, COR, BSX, AVGO, AXON, AJG, ACGL, BRK-B, AFL, CTAS, COST, ATO, AZO, APH, ANET, MO, ALL, BKNG
Holdout Validation
On the last 30% of the sample, the portfolio daily return is the equal-weighted average of constituent simple returns. Cumulative wealth from the start of the holdout is
The same compounding is applied to the S&P 500. Charts compare the cluster book, the unconstrained top-20 Sharpe book, and the index. Because membership is frozen at the training cutoff, the holdout is a genuine out-of-sample path for those fixed names; it is not a walk-forward rebalance.
Out-of-sample wealth paths indexed to 1 at validation start. Period: 2025-05-15 → 2026-11-12.
Conclusion
Clustering on standardised risk–return features forces the portfolio to span distinct regions of the cross-section. Relative to a global Sharpe ranking, the cluster constraint typically gives up some in-sample reward-to-risk in exchange for less concentration in a single statistical neighbourhood. Whether that trade-off survives the holdout is an empirical question the wealth paths are meant to answer for the current sample.
The design omits transaction costs, borrow, and survivorship corrections: the constituent list is not a point-in-time S&P 500 history. Sharpe here is return over volatility, not excess return over a Treasury bill. Treat the page as a methodology for diversification in feature space, and re-run the pipeline when the price panel is refreshed.