# Opportunistic Dark-Pool Execution

`D13-F02-A05` · Execution and Transaction Cost Analysis → Cost/Risk Optimization · archetype `record-transform` · difficulty 5/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/execution-and-transaction-cost-analysis/cost-risk-optimization/opportunistic-dark-pool-execution/
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 { opportunisticDarkPoolExecution } from "fintech-algorithms/execution-and-transaction-cost-analysis/cost-risk-optimization/opportunistic-dark-pool-execution";
```

## Signature

```ts
opportunisticDarkPoolExecution(input)
```

Routes to non-displayed venues to avoid signalling. The counter-risk is adverse selection: filling in the dark exactly when the lit market is about to move against you, which the fill-rate and reversion outputs are there to expose.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `input` | `DarkPoolInput` | yes | Quantity, venue list with their fill characteristics, minimum acceptable quantity, and the reference price constraining acceptable fills. |

## Returns

`{ routes, expected_fill_rate, adverse_selection_estimate, … }`

Routing plan with expected fill rate and an adverse-selection estimate — the cost that dark execution trades for invisibility.

## Errors

- When no venue is supplied — throws

## Complexity

Time `O(venues)`, space `O(venues)`.

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

`input`:

```json
{
  "total_quantity": 6000,
  "lot_size": 100,
  "maximum_dark_fraction_bps": 6000,
  "minimum_firm_probability_bps": 7500,
  "minimum_price_improvement_atoms": 30,
  "minimum_execution_quantity": 300,
  "max_exposure_per_window": 1000,
  "fallback_window": 8,
  "dark_opportunities": [
    {
      "opportunity_id": "DK-01",
      "window": 1,
      "indicated_quantity": 500,
      "firm_probability_bps": 8200,
      "price_improvement_atoms": 50
    },
    {
      "opportunity_id": "DK-02",
      "window": 2,
      "indicated_quantity": 900,
      "firm_probability_bps": 7600,
      "price_improvement_atoms": 40
    },
    {
      "opportunity_id": "DK-03",
      "window": 3,
      "indicated_quantity": 300,
      "firm_probability_bps": 9100,
      "price_improvement_atoms": 60
    }
  ]
}
```

### Call

```ts
opportunisticDarkPoolExecution(input)
```

### Returns

object with 9 fields: total_quantity, maximum_dark_fraction_bps, dark_quantity_cap, planned_dark_exposure_quantity, lit_fallback_quantity, dark_opportunity_count, accepted_dark_window_count, opportunities, …

```json
{
  "total_quantity": 6000,
  "maximum_dark_fraction_bps": 6000,
  "dark_quantity_cap": 3600,
  "planned_dark_exposure_quantity": 3300,
  "lit_fallback_quantity": 2700,
  "dark_opportunity_count": 10,
  "accepted_dark_window_count": 5,
  "opportunities": [
    {
      "opportunity_id": "DK-01",
      "window": 1,
      "indicated_quantity": 500,
      "firm_probability_bps": 8200,
      "price_improvement_atoms": 50,
      "planned_dark_exposure_quantity": 500,
      "reason": "expose-dark",
      "dark_cap_remaining_quantity": 3100
    },
    {
      "opportunity_id": "DK-02",
      "window": 2,
      "indicated_quantity": 900,
      "firm_probability_bps": 7600,
      "price_improvement_atoms": 40,
      "planned_dark_exposure_quantity": 900,
      "reason": "expose-dark",
      "dark_cap_remaining_quantity": 2200
    },
    {
      "opportunity_id": "DK-03",
      "window": 3,
      "indicated_quantity": 300,
      "firm_probability_bps": 9100,
      "price_improvement_atoms": 60,
      "planned_dark_exposure_quantity": 300,
      "reason": "expose-dark",
      "dark_cap_remaining_quantity": 1900
    }
  ],
  "state": "lit-fallback-required"
}
```

## Other exports

`almgrenChrissOptimalExecution`, `implementationShortfallExecution`, `arrivalPriceExecution`, `liquiditySeekingExecution`, `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/execution-and-transaction-cost-analysis/cost-risk-optimization/opportunistic-dark-pool-execution/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/execution-and-transaction-cost-analysis/cost-risk-optimization/opportunistic-dark-pool-execution/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/execution-and-transaction-cost-analysis/llms.txt
