# Sector Diffusion Index

`D04-F05-A04` · Market Breadth and Internals → Concentration and Diffusion · archetype `record-transform` · difficulty 3/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/market-breadth-and-internals/concentration-and-diffusion/sector-diffusion-index/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## 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

```ts
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

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `rows` | `Row[]` | yes | 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. |
| `tolerance` | `number` | yes | Band 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

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`:

```json
[
  {
    "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`:

```json
0.002
```

### Call

```ts
calculate(rows, tolerance)
```

### Returns

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

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

## Verification and provenance

Tier: **verified** (via row-fixture).

The worked example below is the figure published in this algorithm's article, replayed and asserted by the test suite on every build. The arithmetic cannot drift without the build failing.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.1.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/market-breadth-and-internals/concentration-and-diffusion/sector-diffusion-index/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/market-breadth-and-internals/concentration-and-diffusion/sector-diffusion-index/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/market-breadth-and-internals/llms.txt
