fintech-algorithms

Size-Time Priority

Install and import

bash
npm install fintech-algorithms
ts
import { sizeTimePriority } from "fintech-algorithms/matching-engines-and-venue-logic/continuous-matching/size-time-priority";

Signature

sizeTimePriority(incomingRaw, priceRaw, lotRaw, restingRaw)

Orders by size first and arrival second — rewarding large resting orders. Used where a venue wants to attract size rather than speed.

Parameters

NameTypeNotes
incomingRawOrderThe aggressing order.
priceRawnumberPrice level.
lotRawnumberLot size.
min: 1 · integer: true
restingRawOrder[]Resting orders at that price.

Returns

{ fills, residual, ordering, … }

Fills with the priority ordering that produced them.

Errors

  • When lot size is not a positive integer — 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

incomingRaw
650
priceRaw
50
lotRaw
10
restingRaw
[
  {
    "order_id": "ST-1",
    "side": "buy",
    "price": 50,
    "remaining_quantity": 300,
    "arrival_sequence": 10
  },
  {
    "order_id": "ST-2",
    "side": "buy",
    "price": 50,
    "remaining_quantity": 500,
    "arrival_sequence": 30
  },
  {
    "order_id": "ST-3",
    "side": "buy",
    "price": 50,
    "remaining_quantity": 500,
    "arrival_sequence": 20
  }
]

Showing 3 of 4 elements.

Call

sizeTimePriority(incomingRaw, priceRaw, lotRaw, restingRaw)

Returns

object with 9 fields: model, price, lot_size, incoming_quantity, allocated_quantity, unfilled_quantity, ranked_order_ids, allocations, …

{
  "model": "single-price-size-then-time-priority",
  "price": 50,
  "lot_size": 10,
  "incoming_quantity": 650,
  "allocated_quantity": 650,
  "unfilled_quantity": 0,
  "ranked_order_ids": ["ST-3", "ST-2", "ST-1", "ST-4"],
  "allocations": [
    {
      "rank": 1,
      "order_id": "ST-3",
      "resting_quantity": 500,
      "allocated_quantity": 500,
      "remaining_quantity": 0,
      "arrival_sequence": 20
    },
    {
      "rank": 2,
      "order_id": "ST-2",
      "resting_quantity": 500,
      "allocated_quantity": 150,
      "remaining_quantity": 350,
      "arrival_sequence": 30
    }
  ],
  "state": "fully-allocated"
}

Other exports

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

Size-Time Priority — 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