Jason Zou
03Direct indexing basketClaude skill · v0.1.0 · public repository

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.

Output
A five-sheet workbook, a JSON data file and a dashboard, one set per run
Index
Any equity index with a constituent list and a price proxy. The default is the S&P 500 through SPY with 75 names, quarterly rebalancing, a five-year backtest and constrained market-cap weights
Data
Yahoo Finance by default, LSEG or Polygon when connected
Repository
github.com/JasonZou64920/Direct-indexing-basket
Illustrative · Basket size against tracking error

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.

ExplorerS&P 500 · 75 of 500 names · illustrative
kept to match its sector's weightadded to cut tracking errornot held
Hover or tap a sector column for its counts.
Sizes in the sample file
Tracking error1.8%annualised, from the sample file
Correlation0.991daily returns, from the sample file
Names held64 + 11sector picks + tracking-error picks, illustrative

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.

XLSXdirect_index_basket_SPY_75n_YYYYMMDD.xlsx · layout example
Placeholder names and weights, not a run
CompanySectorBasketIndexTiltRole
Name AInformation Technology6.10%5.40%+0.70%Mega-cap anchor
Name BInformation Technology5.20%4.90%+0.30%Mega-cap anchor
Name CHealth Care3.80%2.60%+1.20%Sector proxy
Name DFinancials3.50%2.20%+1.30%Sector proxy
Name EIndustrials2.40%1.10%+1.30%Tracking-error fill
…
75 names100.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.

Example values, not a run
SectorBasketIndexDelta
Information Technology31.20%31.80%−0.60%
Financials13.10%12.80%+0.30%
Health Care10.80%11.10%−0.30%
Consumer Discretionary10.40%10.10%+0.30%
Communication Services9.20%9.40%−0.20%
Industrials8.10%7.90%+0.20%
Consumer Staples5.80%6.00%−0.20%
Energy3.90%3.70%+0.20%
Utilities2.60%2.50%+0.10%
Real Estate2.50%2.40%+0.10%
Materials2.40%2.30%+0.10%
All 11 sectors100.00%100.00%0.00%

The sheet has one row for each benchmark sector, including any sector the basket does not cover.

Example values, not a run · click a size

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.

MetricHow it is computed
Tracking errorAnnualised, from daily adjusted-close returns of the basket and the index over the horizon
CorrelationDaily 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, drawdownAnnualised return and volatility and the maximum drawdown for both, with each gap reported as basket minus index
Up and down captureBasket move relative to the index in up markets and in down markets
Beat diagnosticsMonthly 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

The Meta sheet records the as-of date, the benchmark with its ticker and constituent count, the basket size, the construction and weighting method, the rebalance frequency, the backtest window and the data source actually used, then a methodology paragraph and one row per disclaimer.

The same disclaimer ships with every run. It says the output is research support and not investment, legal or tax advice, and that backtested tracking is historical and hypothetical, excludes costs and taxes, and may not persist out of sample.

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.

XLSX
Five sheets (Holdings, Sector Exposure, Size Sensitivity, KPIs & Stats and Meta) with the header rows frozen. Weights are stored as decimals with a percent format, not as text
JSON
The data file the dashboard reads. It also records the inputs the run settled on and the data source it used
JSX
A fixed dashboard layout where only the data changes from run to run. It shows a KPI strip, cumulative performance, rolling correlation, cumulative active return, sector bars, holdings, tracking and beat diagnostics, methodology and risks

The window shows the workbook's layout, with placeholder names and example values from the skill's sample file.

03MethodStratified sampling

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.

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.

03Who does what

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)

Notes

Placeholder names

A real basket published here would look like a portfolio recommendation, which the tool doesn't make. So this page uses example values from the skill's sample file. Running it yourself gives real figures labelled with the data source.

Outperformance

The basket is built to track the index. Beating it is not a goal, and the skill's rules forbid presenting outperformance as one or as an expectation. The beat diagnostics only report whether the basket happened to outperform over the window, month by month and in up and down markets.