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

Effective Number of Constituents

Install and import#

bash
npm install fintech-algorithms
ts
import { calculate } from "fintech-algorithms/market-breadth-and-internals/concentration-and-diffusion/effective-number-of-constituents";

Signature#

calculate(rows)

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.

Parameters#

NameTypeNotes
rowsRow[]Constituents with weights. Rows carry a ready flag; a row that is not ready is excluded rather than treated as zero, because a missing count and a count of zero mean opposite things about market breadth.

Returns#

{ status, effective_n, actual_n, hhi }

The effective count beside the actual count — the gap between them is the entire message.

Errors#

  • When weights do not sum to approximately 1 — reported as a status rather than thrown

Complexity: time O(n), space O(1).

Worked example#

executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

Input#

rows
[
  {
    "security_id": "S01",
    "weight": 0.17821782178217824,
    "return": 0.065,
    "sector": "Tech",
    "ready": true
  },
  {
    "security_id": "S02",
    "weight": 0.13861386138613863,
    "return": 0.041,
    "sector": "Financials",
    "ready": true
  },
  {
    "security_id": "S03",
    "weight": 0.10891089108910892,
    "return": 0.028,
    "sector": "Industrials",
    "ready": true
  }
]

Showing 3 of 24 elements.

Call#

calculate(rows)

Returns#

object with 4 fields: status, effective_n, actual_n, hhi

{
  "status": "resolved",
  "effective_n": 11.134761062719665,
  "actual_n": 24,
  "hhi": 0.0898088422703657
}

Diagrams#

Effective Number of Constituents — decision boundary
Effective Number of Constituents — family map

Calculation flow#

Calculation Flow — Effective Number of Constituents
flowchart LR
    A["Point-in-time component snapshot"] --> B{"Complete, unique, finite?"}
    B -->|"No"| X["Incomplete — withhold value"]
    B -->|"Yes"| C["Apply Effective Number of Constituents contract"]
    C --> D["Retain component audit trace"]
    D --> E["Publish value, unit, parameter, and as-of"]

How it works#

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References#

The rest of the Concentration and Diffusion family#