# Index Replication-Cost Estimator

`D03-F06-A08` · 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/index-replication-cost-estimator/
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/index-replication-cost-estimator";
```

## Signature

```ts
calculate(data)
```

Estimates what a rebalance costs to implement — spread, market impact and commission. This is where the rulebook meets reality: a screen that looks clean on paper can be expensive to track.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `data` | `{ trades: Trade[] }` | yes | Each trade carries size, spread and the liquidity measures the impact model consumes. |

## Returns

`{ results, estimatedCost, costBpsOnGrossTrade }`

Per-trade costs plus the total in basis points of gross traded value, which is the unit these are compared in.

## Errors

- When a trade is missing a liquidity input the model requires — recorded on the result rather than thrown

## Complexity

Time `O(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
{
  "trades": [
    {
      "id": "A",
      "tradeValue": 12000000,
      "spreadBps": 6,
      "impactCoefficientBps": 18,
      "participation": 0.08
    },
    {
      "id": "B",
      "tradeValue": -7000000,
      "spreadBps": 10,
      "impactCoefficientBps": 25,
      "participation": 0.12
    },
    {
      "id": "C",
      "tradeValue": 3500000,
      "spreadBps": 14,
      "impactCoefficientBps": 30,
      "participation": 0.18
    }
  ]
}
```

### Call

```ts
calculate(data)
```

### Returns

object with 3 fields: results, estimatedCost, costBpsOnGrossTrade

```json
{
  "results": [
    {
      "id": "A",
      "spreadCost": 3600,
      "impactCost": 6109.402589,
      "totalCost": 9709.402589
    },
    {
      "id": "B",
      "spreadCost": 3500,
      "impactCost": 6062.177826,
      "totalCost": 9562.177826
    },
    {
      "id": "C",
      "spreadCost": 2450,
      "impactCost": 4454.772721,
      "totalCost": 6904.772721
    }
  ],
  "estimatedCost": 28401.098007,
  "costBpsOnGrossTrade": 11.360439
}
```

## 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/index-replication-cost-estimator/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/index-and-benchmark-engineering/governance-and-maintenance/index-replication-cost-estimator/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
