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

Sector Diffusion Index

Install and import#

bash
npm install fintech-algorithms
ts
import { calculate } from "fintech-algorithms/market-breadth-and-internals/concentration-and-diffusion/sector-diffusion-index";

Signature#

calculate(rows, tolerance)

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.

Parameters#

NameTypeNotes
rowsRow[]One row per sector carrying its signal change. 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.
tolerancenumberBand within which a change counts as unchanged rather than improving or deteriorating. Without it, floating-point noise makes everything move.
min: 0

Returns#

{ status, value, improving, unchanged, deteriorating, total }

The diffusion value with the three counts behind it.

Errors#

  • When tolerance is negative — throws

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
[
  {
    "component_id": "Communication",
    "signal_change": 0.012,
    "ready": true
  },
  {
    "component_id": "Consumer Discretionary",
    "signal_change": 0.008,
    "ready": true
  },
  {
    "component_id": "Consumer Staples",
    "signal_change": 0.006,
    "ready": true
  }
]

Showing 3 of 11 elements.

tolerance
0.002

Call#

calculate(rows, tolerance)

Returns#

object with 6 fields: status, value, improving, unchanged, deteriorating, total

{
  "status": "resolved",
  "value": 59.09090909090909,
  "improving": 5,
  "unchanged": 3,
  "deteriorating": 3,
  "total": 11
}

Diagrams#

Sector Diffusion Index — decision boundary
Sector Diffusion Index — family map

Calculation flow#

Calculation Flow — Sector Diffusion Index
flowchart LR
    A["Point-in-time component snapshot"] --> B{"Complete, unique, finite?"}
    B -->|"No"| X["Incomplete — withhold value"]
    B -->|"Yes"| C["Apply Sector Diffusion Index 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#