fintech-algorithms

Hybrid Pro-Rata/Time Matching

Install and import

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

Signature

calculate(topicId, inputs)

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
topicIdstringTopic identifier selecting the matching variant.
inputsMatchingInputThe aggressing order, the resting book, and the split between the time-priority and pro-rata portions.

Returns

{ fills, allocations, residual, split, … }

Fills from both portions with the split applied.

Errors

  • When the split fractions do not sum to 1 — throws

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

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

topicId
"D12-F01-A04"
inputs
{
  "incoming_quantity": 600,
  "price": 100,
  "lot_size": 1,
  "fifo_fraction": 0.4,
  "resting_orders": [
    {
      "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

calculate(topicId, inputs)

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, hybridProRataTime. 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

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