fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Closing-Cross Price

Install and import#

bash
npm install fintech-algorithms
ts
import { closingCrossPrice } from "fintech-algorithms/matching-engines-and-venue-logic/auctions/closing-cross-price";

Signature#

closingCrossPrice(orders, reference, tick, low, high)

The closing auction, which sets the price index funds actually trade at. Same criteria as the open, different reference and typically a tighter permitted band.

Parameters#

NameTypeNotes
ordersOrder[]Orders entered into the closing auction.
referencenumberReference price for tie-breaking.
ticknumberTick size in atoms.
min: 1 · integer: true
lownumberLower bound of the permitted range.
highnumberUpper bound.

Returns#

{ price, volume, imbalance, criterion_applied, … }

The closing price with the deciding criterion.

Errors#

  • When low exceeds high, or no order crosses — reported as a status rather than thrown

Complexity: time O(orders log orders), space O(prices).

Worked example#

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

orders
[
  {
    "order_id": "MOC-B",
    "side": "buy",
    "order_type": "MOC",
    "price": null,
    "quantity": 300,
    "arrival_sequence": 10
  },
  {
    "order_id": "LOC-B101",
    "side": "buy",
    "order_type": "LOC",
    "price": 101,
    "quantity": 350,
    "arrival_sequence": 20
  },
  {
    "order_id": "DAY-B100",
    "side": "buy",
    "order_type": "DAY",
    "price": 100,
    "quantity": 250,
    "arrival_sequence": 30
  }
]

Showing 3 of 7 elements.

reference
100
tick
1
low
95
high
105

Call#

closingCrossPrice(orders, reference, tick, low, high)

Returns#

object with 15 fields: model, session, reference_price, collar_low, collar_high, eligible_order_count, selected_price, executed_quantity, …

{
  "model": "declared-closing-cross",
  "session": "closing",
  "reference_price": 100,
  "collar_low": 95,
  "collar_high": 105,
  "eligible_order_count": 7,
  "selected_price": 100,
  "executed_quantity": 700,
  "buy_quantity": 900,
  "sell_quantity": 700,
  "imbalance_quantity": 200,
  "imbalance_side": "buy",
  "selection_trace": [
    "maximize executable quantity at 700",
    "minimize absolute imbalance at 200",
    "the objective hierarchy leaves one price"
  ],
  "candidate_evaluations": [
    {
      "price": 99,
      "buy_quantity": 900,
      "sell_quantity": 400,
      "executable_quantity": 400,
      "imbalance_quantity": 500,
      "absolute_imbalance": 500,
      "imbalance_side": "buy"
    },
    {
      "price": 100,
      "buy_quantity": 900,
      "sell_quantity": 700,
      "executable_quantity": 700,
      "imbalance_quantity": 200,
      "absolute_imbalance": 200,
      "imbalance_side": "buy"
    },
    {
      "price": 101,
      "buy_quantity": 650,
      "sell_quantity": 1150,
      "executable_quantity": 650,
      "imbalance_quantity": -500,
      "absolute_imbalance": 500,
      "imbalance_side": "sell"
    }
  ]
}

Showing 14 of 15 fields.

Other exports#

This module also exports maximumExecutableVolumeAuction, minimumImbalanceTieBreak, openingCrossPrice, volatilityAuctionReopening, 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.

Diagrams#

Closing-Cross Price — system map

Calculation flow#

Closing-Cross Price calculation flow
flowchart LR
    S1["Validate MOC LOC and DAY eligibility"]
    S2["Build candidates inside the closing collar"]
    S3["Maximize executable quantity"]
    S4["Minimize imbalance then apply surplusreference rules"]
    S5["Return closing price volume imbalance and trace"]
    S1 --> S2
    S2 --> S3
    S3 --> S4
    S4 --> S5
    S5 --> D{"closingonly eligibility and a nocross officialprice gap"}
    D --> O["selected_price + diagnostics"]
    O --> A["Audit: Openingonly MOO and LOO orders are unsupported"]

How it works#

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References#

The rest of the Auctions family#