# Roll Spread Estimator

`D11-F02-A04` · Market Microstructure → Liquidity and Spreads · archetype `record-transform` · difficulty 4/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/market-microstructure/liquidity-and-spreads/roll-spread-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 { rollSpread } from "fintech-algorithms/market-microstructure/liquidity-and-spreads/roll-spread-estimator";
```

## Signature

```ts
rollSpread(prices)
```

Infers the effective spread from the negative serial covariance of price changes alone — no quote data required. When the covariance comes out positive the model is contradicted, and reporting zero rather than an imaginary number is the honest handling.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `prices` | `number[]` | yes | Trade price series, chronological. |

## Returns

`{ spread, covariance, valid, … }`

The implied spread with the covariance behind it and a validity flag for the positive-covariance case.

## Errors

- When fewer than three prices are supplied — 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

`prices`:

```json
[100, 100.05, 100.01, 100.06, 100.02, 100.07]
```

### Call

```ts
rollSpread(prices)
```

### Returns

object with 11 fields: model, observation_count, change_count, covariance_pair_count, lag1_price_change_covariance, covariance_tolerance, mean_price, spread_estimate, …

```json
{
  "model": "roll-spread",
  "observation_count": 6,
  "change_count": 5,
  "covariance_pair_count": 4,
  "lag1_price_change_covariance": -0.0026999999999997785,
  "covariance_tolerance": 1e-15,
  "mean_price": 100.03500000000001,
  "spread_estimate": 0.10392304845412838,
  "spread_estimate_relative": 0.0010388668811328872,
  "spread_estimate_bps": 10.388668811328872,
  "state": "estimated"
}
```

## Other exports

`quotedSpread`, `effectiveSpread`, `realizedSpread`, `amihudIlliquidity`, `corwinSchultzSpread`, `calculate`. Every module additionally exports `run` as an alias of its primary
function, and a `meta` object carrying its catalog id, domain, family, shape and article URL.

## Verification and provenance

Tier: **verified** (via D).

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-microstructure/liquidity-and-spreads/roll-spread-estimator/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/market-microstructure/liquidity-and-spreads/roll-spread-estimator/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/market-microstructure/llms.txt
