Diversified Stock Portfolio Using Clustering Analysis

correlation beta returns volatility Sharpe ratio backtesting

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_returnann_volann_sharpe…ann_daily_…ann_daily_…betacor
ann_return1.000-0.2340.946-0.731-0.233-0.1530.674
ann_vol-0.2341.000-0.2860.3550.9750.839-0.178
ann_sharpe…0.946-0.2861.000-0.703-0.269-0.2010.688
ann_daily_…-0.7310.355-0.7031.0000.3960.190-0.639
ann_daily_…-0.2330.975-0.2690.3961.0000.786-0.188
beta-0.1530.839-0.2010.1900.7861.0000.118
cor0.674-0.1780.688-0.639-0.1880.1181.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.

ClusterCountReturnVolSharpeBeta
17111.200%24.400%0.4760.619
219-19.300%54.600%-0.3781.610
34316.300%37.800%0.4191.266
460-6.600%30.400%-0.2150.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.

QuantifiedTrader logoQuantifiedTrader

Independent quantitative research on trading methods, backtesting, and market analytics.

Research disclaimer

QuantifiedTrader is operated by an independent quantitative research group. We study, document, and compare different methods of trading, portfolio construction, risk management, and investment analysis. Our work is exploratory and academic in nature—we build tools, run backtests, and publish findings to advance understanding, not to promote any particular strategy or product.

Not investment advice. Nothing on this website constitutes investment, trading, financial, tax, legal, or other professional advice. We do not recommend, endorse, or solicit the purchase or sale of any security, derivative, or financial instrument, nor do we suggest that any strategy, model, or result presented here is suitable for any individual or institution. Any examples, simulations, or performance figures are illustrative research outputs only.

No client or advisory relationship. We do not provide investment advisory, brokerage, portfolio-management, custody, or asset-management services to any person or entity. Browsing this site, using our tools, or contacting us does not create a client, fiduciary, or advisory relationship. We do not manage money on behalf of third parties and do not act as agents for any financial institution.

Research & education only. Content, datasets, backtests, charts, code, and software made available here are for informational and educational research. Materials may be incomplete, simulated, hypothetical, or derived from third-party sources that we do not control. Past performance, backtested results, and historical analyses are not indicative of future results. Market conditions change; models may fail; assumptions may be wrong. You are solely responsible for evaluating any information and for all decisions you make.

No responsibility or liability. To the fullest extent permitted by applicable law, QuantifiedTrader and its contributors disclaim all responsibility and liability for any loss, damage, cost, or expense—direct or indirect—arising from access to, use of, or reliance on this website, its content, or its tools. All materials are provided “as is” and “as available,” without warranties of any kind, whether express or implied, including but not limited to accuracy, completeness, fitness for a particular purpose, or non-infringement.

Non-commercial research sharing. This site does not aim to profit from the knowledge, tools, or datasets published here. Materials are shared for non-commercial research and learning, subject to applicable open-source or site terms where noted. We are a research collective, not a commercial product or service provider.

Contact. For questions about this notice, the site, or published research materials, contact support@quantedx.com. Correspondence is for administrative and research purposes only and does not constitute advice or create any professional obligation on our part.

© 2026 QuantifiedTrader. All rights reserved.