Portfolio diversification metrics for an API.
Holding count is the least informative diversification metric. A useful API measures how capital and common drivers are distributed—and tells you when its evidence is incomplete.
Start with portfolio weights
Convert each positive market value into a fraction of total invested value. Preserve cash as a separate exposure because including it as if it were a security distorts concentration. Validate that values are finite and positive; never let a malformed position quietly change the denominator.
Maximum position weight
The largest position catches an obvious single-name dependency. It is easy to explain and useful as an alert threshold, but it ignores the rest of the distribution. Five equal positions can have an acceptable-looking maximum weight while the portfolio is still highly concentrated.
HHI and effective positions
HHI = Σ wᵢ² N-effective = 1 / HHISquaring gives large positions disproportionate influence. Inverting HHI translates the result into an intuitive equivalent count: the number of equally weighted positions that would have the same concentration. A thirty-name portfolio with an effective count of six behaves, by this measure, like six equal positions.
Use both fields. HHI is convenient for calculation and comparison; effective positions is easier to explain. The worked concentration guide shows the arithmetic.
Repeat the calculation by sector
Position-level diversification is not enough. Ten stocks can all belong to technology, banks, or oil producers. Group weights by sector, identify the top sector and its weight, and calculate a sector concentration measure. Your UI should show position and sector findings separately so one cannot cancel the other inside a composite score.
Add factor evidence carefully
Sector labels are only a proxy for common behaviour. Holdings in different sectors can share sensitivity to interest rates, currencies, equity indices, or commodities. Factor correlations and betas can reveal those shared drivers, but they are historical estimates. An API should attach horizon, confidence, and stability information rather than presenting correlation as a permanent property.
Make coverage part of the output
If factor evidence is available for only half the invested weight, a diversification verdict based on factors must be qualified. Report matched weight, low-confidence weight, missing weight, and the tickers affected. Missing evidence is not proof of diversification.
Example response slice
{
"max_position_weight": 45.45,
"max_position_ticker": "AAPL",
"effective_positions": 2.58,
"top_sector": "Technology",
"top_sector_weight": 100.0,
"score_components": {
"diversification": 34.5,
"risk": 99.2
},
"diagnostics": {
"factor_evidence": {
"quality": "medium",
"missing_weight_pct": 18.0
}
}
}
The disagreement is the finding: individually stable holdings do not make a sector-concentrated portfolio diversified.
Implementation rules
- Calculate on market-value weights, not raw share counts.
- Keep cash and uninvested value explicit.
- Return maximum weight, HHI or effective positions, and sector concentration.
- Never convert missing classifications or factor fields to zero.
- Show coverage and confidence beside the verdict.
- Use risk-profile targets as context, not universal laws.
For a complete request and response contract, see the PORTIQA API reference.