fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Concentration and Diffusion

5 algorithms in Market Breadth and Internals · 5 with asserted arithmetic.

In this family#

  1. Top-N Index Contribution verified

    How much of an index's move came from its largest N members. This is the arithmetic behind 'seven stocks are holding up the market' — a claim that is usually asserted and rarely measured.

    calculate(rows, topN)
  2. Herfindahl Constituent Concentration verified

    The Herfindahl–Hirschman index of constituent weights: the sum of squared weights. Squaring is what makes it a concentration measure — it is dominated by the largest holdings in a way a simple count never is.

    calculate(rows)
  3. Effective Number of Constituents verified

    The reciprocal of HHI: how many equally weighted holdings would give the same concentration. An index of 500 names with an effective number of 60 is, for risk purposes, a 60-stock portfolio.

    calculate(rows)
  4. Sector Diffusion Index verified

    The share of sectors improving rather than deteriorating. Diffusion asks how *broad* a move is across groups, which a capitalisation-weighted index cannot show — one sector can carry the whole level.

    calculate(rows, tolerance)
  5. Factor Diffusion Index verified

    The same diffusion measure across factors rather than sectors — momentum, size, volatility — showing whether a move is broad across styles or concentrated in one.

    calculate(rows, tolerance)

What they share#

Every topic here is a record-transform, so once you have called one the rest follow the same shape. Import paths differ only in the final segment:

ts
import { calculate } from "fintech-algorithms/market-breadth-and-internals/concentration-and-diffusion/top-n-index-contribution";
import { calculate } from "fintech-algorithms/market-breadth-and-internals/concentration-and-diffusion/herfindahl-constituent-concentration";

Read them in the order above — the sequence is pedagogical, not alphabetical.

Where this sits#

Market Breadth and Internals collects 28 algorithms across 5 families. For the concept behind this family rather than the call signatures, see the concept guides.