# Reconstitution Algorithm

`D03-F06-A05` · Index and Benchmark Engineering → Governance and Maintenance · archetype `record-transform` · difficulty 4/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/index-and-benchmark-engineering/governance-and-maintenance/reconstitution-algorithm/
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/index-and-benchmark-engineering/governance-and-maintenance/reconstitution-algorithm";
```

## Signature

```ts
calculate(data)
```

Chooses the membership at a scheduled review, using an incumbent buffer so a name hovering at the boundary is not swapped in and out every period. The buffer is what separates an index from a churn machine.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `data` | `{ candidates: Candidate[]; targetCount: number; incumbentBuffer: number }` | yes | `incumbentBuffer` lets an existing member stay while it ranks within the buffer beyond the cutoff — asymmetric on purpose, because turnover costs the tracking funds real money. |

## Returns

`{ selectedIds, additions, deletions, targetCount }`

The new membership with the explicit adds and drops it implies.

## Errors

- When targetCount exceeds the candidate count — throws

## Complexity

Time `O(n log n)`, space `O(n)`.

## Worked example

This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

### Input

`data`:

```json
{
  "candidates": [
    {
      "id": "A",
      "score": 98,
      "incumbent": true
    },
    {
      "id": "B",
      "score": 94,
      "incumbent": true
    },
    {
      "id": "C",
      "score": 90,
      "incumbent": false
    }
  ],
  "targetCount": 5,
  "incumbentBuffer": 1
}
```

### Call

```ts
calculate(data)
```

### Returns

object with 4 fields: selectedIds, additions, deletions, targetCount

```json
{
  "selectedIds": ["A", "B", "C", "D", "F"],
  "additions": ["C"],
  "deletions": [],
  "targetCount": 5
}
```

## Verification and provenance

Tier: **verified** (via input-expected).

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/index-and-benchmark-engineering/governance-and-maintenance/reconstitution-algorithm/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/index-and-benchmark-engineering/governance-and-maintenance/reconstitution-algorithm/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/index-and-benchmark-engineering/llms.txt
