Tracking an index with fewer names
Direct indexing means holding an index's stocks directly, so an account can avoid unwanted names and realise losses. Most accounts can't hold every constituent. This Claude skill, a folder of instructions and scripts, builds a smaller basket to track the index and backtests several sizes.
How many names the basket needs
Move the slider to change the basket size and see what fewer names cost in tracking error. Each dot is one of the index's roughly 500 constituents, sorted by market cap within its sector. The figures are illustrative, based on the skill's sample file.
The curve flattens quickly. Going from 50 to 75 names takes about a point off the tracking error; going from 75 to 100 takes off less than half a point more. The workbook's Size Sensitivity sheet reports the measured figures for the sizes a run actually built.
| Company | Sector | Basket | Index | Tilt | Role |
|---|---|---|---|---|---|
| Name A | Information Technology | 6.10% | 5.40% | +0.70% | Mega-cap anchor |
| Name B | Information Technology | 5.20% | 4.90% | +0.30% | Mega-cap anchor |
| Name C | Health Care | 3.80% | 2.60% | +1.20% | Sector proxy |
| Name D | Financials | 3.50% | 2.20% | +1.30% | Sector proxy |
| Name E | Industrials | 2.40% | 1.10% | +1.30% | Tracking-error fill |
| … | |||||
| 75 names | 100.00% |
The real sheet is sorted by weight, with a ticker and one-line note per holding. Weights sum to exactly 1.0000, and the largest weight absorbs any floating-point residual.
| Sector | Basket | Index | Delta |
|---|---|---|---|
| Information Technology | 31.20% | 31.80% | −0.60% |
| Financials | 13.10% | 12.80% | +0.30% |
| Health Care | 10.80% | 11.10% | −0.30% |
| Consumer Discretionary | 10.40% | 10.10% | +0.30% |
| Communication Services | 9.20% | 9.40% | −0.20% |
| Industrials | 8.10% | 7.90% | +0.20% |
| Consumer Staples | 5.80% | 6.00% | −0.20% |
| Energy | 3.90% | 3.70% | +0.20% |
| Utilities | 2.60% | 2.50% | +0.10% |
| Real Estate | 2.50% | 2.40% | +0.10% |
| Materials | 2.40% | 2.30% | +0.10% |
| All 11 sectors | 100.00% | 100.00% | 0.00% |
The sheet has one row for each benchmark sector, including any sector the basket does not cover.
Bar length is annualised tracking error, so shorter is better. The sheet highlights the row for the chosen size, and clicking a size here does the same.
| Metric | How it is computed |
|---|---|
| Tracking error | Annualised, from daily adjusted-close returns of the basket and the index over the horizon |
| Correlation | Daily returns over the full period, plus a rolling 60-trading-day series with its mean, minimum and maximum |
| Beta and R² | Basket returns regressed on index returns |
| Return, volatility, drawdown | Annualised return and volatility and the maximum drawdown for both, with each gap reported as basket minus index |
| Up and down capture | Basket move relative to the index in up markets and in down markets |
| Beat diagnostics | Monthly and rolling 12-month beat rates (how often the basket beat the index), the same in up and down markets, the average annualised excess return, and the best and worst month. Reported for information only; the basket is built to track the index |
Outputs
A run writes three files, named after the benchmark, the basket size and the date. The workbook is the one a reviewer opens. The dashboard reads the JSON file.
The window shows the workbook's layout, with placeholder names and example values from the skill's sample file.
How the basket is built
The steps below follow the default method, stratified sampling, which keeps each sector's largest names and fills the remaining slots to cut tracking error. I chose it as the easiest to explain. The skill also offers representative sampling, correlation maximisation, constrained tracking-error minimisation and hybrids.
- Set the inputs. The inputs default to the S&P 500 with SPY as its price proxy, 75 names, quarterly rebalancing, a five-year backtest and constrained market-cap weights. If you give a basket size, the tool uses exactly that number.
- Build the eligible universe. The tool drops any name without a continuous adjusted-close price history over the backtest window, and any name below the liquidity and market-cap floors. It records the size of the universe that remains and any material exclusions.
- Stratify by sector. The tool splits the benchmark into its GICS sectors and keeps the largest names in each sector until the names held add up to that sector's weight in the index.
- Fill for tracking error. The remaining slots go to the names that most reduce expected tracking error, estimated from past returns. The fill stays within a sector tolerance, a maximum weight per name, minimum liquidity, a market-cap floor and a turnover cap.
- Set the weights. Weights start from market cap, are capped per name and then rescaled so each sector matches its target weight. The tool records the active tilt of every holding. Equal weighting is used only when chosen on purpose.
- Backtest and vary the size. The tool backtests the basket on daily adjusted-close returns over the window, then recomputes tracking error and correlation at two or more other basket sizes.
Backtest and size sensitivity
The backtest is run on daily returns rather than on price levels. The size sensitivity reruns the build at other basket sizes and reports the tracking error at each one, which is what you need to know before you settle on a number.
Daily returns
The backtest reports cumulative performance rebased to 100, annualised tracking error, beta and R², annualised volatility and maximum drawdown for both the basket and the index, and up- and down-market capture. All of it comes from daily adjusted-close returns over the backtest window.
Rolling correlation
The window is 60 trading days by default. The tool reports the mean, minimum and maximum of the rolling series next to the full-period correlation. If the basket stopped tracking for a while, that shows up as a dip in the rolling series even when the full-period figure still looks fine.
Beat diagnostics
The tool reports how often the basket beat the index monthly, over rolling 12-month windows and in up and down markets. It also gives average annualised excess return and the best and worst month. Outperformance is not a goal.
Size sensitivity
The tool recomputes tracking error and correlation at two or more other sizes, for example the chosen size plus and minus 25 names. Smaller baskets are simpler to hold but usually track worse, and the sheet shows by how much.
Limits of the backtest
The backtest ignores transaction costs, taxes and slippage, so actual tracking error will be somewhat worse. It uses today's constituents, which understates the drag from former constituents. It is also in-sample, so the reported tracking error is a lower bound.
Prices
Prices come from Yahoo Finance through yfinance by default, or from LSEG or Polygon when one of those is connected. Web search is used only for constituent lists and sector tags, not for prices. If there is no price source, the run stops and says what is missing.
The tool
- Screening the index for price history, liquidity and size
- Picking names by sector, filling for tracking error and capping weights
- Running the backtest and size sensitivity, writing the five-sheet workbook
- Stopping when there is no price source instead of inventing prices, weights or statistics
You
- Choosing the basket size and the constraints
- Deciding whether the tracking error is acceptable for the account
- Any tax or wash-sale decision, which the tool does not make
- Weighing the limits above (survivorship bias from using current constituents, no trading costs or taxes, drift out of sample)