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

Hybrid Pro-Rata/Time Matching

Install and import#

bash
npm install fintech-algorithms
ts
import { hybridProRataTime } from "fintech-algorithms/matching-engines-and-venue-logic/continuous-matching/hybrid-pro-rata-time-matching";

Signature#

hybridProRataTime(incomingRaw, priceRaw, lotRaw, fractionRaw, restingRaw)

Splits an incoming order between a time-priority portion and a pro-rata portion — the compromise most futures venues actually run, because pure pro-rata invites size inflation and pure price-time invites a latency race.

Parameters#

NameTypeNotes
incomingRawnumberQuantity of the aggressing order. Only the part the resting book can fill is allocated; the rest comes back as unfilled_quantity.
priceRawnumberThe single price this match happens at. Echoed back as price.
lotRawnumberLot size. Allocation is computed in whole lots, so both portions are shared out in units of this rather than in raw quantity.
fractionRawnumberShare of the executable quantity allocated by arrival order before the remainder goes pro rata. Zero is pure pro-rata; one is pure time priority.
min: 0 · max: 1
restingRawRestingOrder[]The resting book at this price, each order carrying order_id, remaining_quantity and arrival_sequence.

Returns#

{ model, price, lot_size, fifo_fraction, incoming_quantity, executable_quantity, fifo_target_quantity, pro_rata_target_quantity, allocated_quantity, unfilled_quantity, allocations, state }

Both target quantities, and allocations ordered by arrival with each order's fill split into fifo_quantity and pro_rata_quantity. state is fully-allocated or partially-allocated.

Errors#

  • When fractionRaw is below zero or above one — throws RangeError

Complexity: time O(resting log resting), space O(resting).

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#

incomingRaw
600
priceRaw
100
lotRaw
1
fractionRaw
0.4
restingRaw
[
  {
    "order_id": "H-1",
    "side": "sell",
    "price": 100,
    "remaining_quantity": 500,
    "arrival_sequence": 10
  },
  {
    "order_id": "H-2",
    "side": "sell",
    "price": 100,
    "remaining_quantity": 300,
    "arrival_sequence": 20
  },
  {
    "order_id": "H-3",
    "side": "sell",
    "price": 100,
    "remaining_quantity": 200,
    "arrival_sequence": 30
  }
]

Call#

hybridProRataTime(incomingRaw, priceRaw, lotRaw, fractionRaw, restingRaw)

Returns#

object with 12 fields: model, price, lot_size, fifo_fraction, incoming_quantity, executable_quantity, fifo_target_quantity, pro_rata_target_quantity, …

{
  "model": "single-price-fifo-pro-rata-split",
  "price": 100,
  "lot_size": 1,
  "fifo_fraction": 0.4,
  "incoming_quantity": 600,
  "executable_quantity": 600,
  "fifo_target_quantity": 240,
  "pro_rata_target_quantity": 360,
  "allocated_quantity": 600,
  "unfilled_quantity": 0,
  "allocations": [
    {
      "order_id": "H-1",
      "resting_quantity": 500,
      "fifo_quantity": 240,
      "pro_rata_quantity": 123,
      "allocated_quantity": 363,
      "remaining_quantity": 137,
      "arrival_sequence": 10
    },
    {
      "order_id": "H-2",
      "resting_quantity": 300,
      "fifo_quantity": 0,
      "pro_rata_quantity": 142,
      "allocated_quantity": 142,
      "remaining_quantity": 158,
      "arrival_sequence": 20
    },
    {
      "order_id": "H-3",
      "resting_quantity": 200,
      "fifo_quantity": 0,
      "pro_rata_quantity": 95,
      "allocated_quantity": 95,
      "remaining_quantity": 105,
      "arrival_sequence": 30
    }
  ],
  "state": "fully-allocated"
}

Other exports#

This module also exports priceTimePriority, proRataMatching, sizeTimePriority, 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#

Hybrid Pro-Rata/Time Matching — system map

Calculation flow#

Hybrid Pro-Rata/Time Matching calculation flow
flowchart LR
    S1["Validate the oneprice book and fraction"]
    S2["Compute executable whole lots"]
    S3["Floor the FIFO target and allocate oldest orders first"]
    S4["Recompute residual resting capacity"]
    S5["Allocate the remaining target pro rata and reconcile"]
    S1 --> S2
    S2 --> S3
    S3 --> S4
    S4 --> S5
    S5 --> D{"zeroone split endpoints and capacity doublecount preventio"}
    D --> O["allocated_quantity + diagnostics"]
    O --> A["Audit: FIFO and prorata targets sum to executable quantity"]

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 Continuous Matching family#