# Effective Spread

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

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

## Signature

```ts
effectiveSpread(bid, ask, tradePrice, side)
```

Twice the signed distance from the midpoint to the trade price — what the trade actually paid. Narrower than the quoted spread when trades execute inside it, wider when they sweep.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `bid` | `number` | yes | Best bid at the time of the trade. |
| `ask` | `number` | yes | Best ask at the time of the trade. |
| `tradePrice` | `number` | yes | Executed price. |
| `side` | `"buy" \| "sell"` | yes | Trade direction, usually from a classifier in D11-F01. |

## Returns

`{ effective_spread, relative, midpoint, price_improvement }`

The effective spread and the price improvement against the quote.

## Errors

- When side is not buy or sell, or ask is below bid — throws

## Complexity

Time `O(1)`, 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

`bid`:

```json
100
```

`ask`:

```json
100.08
```

`tradePrice`:

```json
100.07
```

`side`:

```json
"buy"
```

### Call

```ts
effectiveSpread(bid, ask, tradePrice, side)
```

### Returns

object with 17 fields: model, bid, ask, midpoint, quoted_spread, quoted_spread_relative, quoted_spread_bps, state, …

```json
{
  "model": "effective-spread",
  "bid": 100,
  "ask": 100.08,
  "midpoint": 100.03999999999999,
  "quoted_spread": 0.0799999999999983,
  "quoted_spread_relative": 0.0007996801279488034,
  "quoted_spread_bps": 7.996801279488034,
  "state": "inside-quote",
  "trade_price": 100.07,
  "side": "buy",
  "direction": 1,
  "effective_spread": 0.060000000000002274,
  "effective_spread_relative": 0.0005997600959616381,
  "effective_spread_bps": 5.997600959616381
}
```

Showing 14 of 17 fields.

## Other exports

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