Skip to content

quantpylib.hft.replay_stream

NearlyOrderedToOrderedIterator converts a physically ordered source with bounded timestamp disorder into deterministic key order. Records that arrive later than the configured lookahead window are dropped and counted.

API

quantpylib.hft.replay_stream.NearlyOrderedToOrderedIterator

Order a nearly sorted stream with bounded record lookahead.

Items are retained in a sorted deque until the buffer is filled to lookahead size and emits records in order. A reverse linear insertion makes use of the near sorted property to make this ordering efficient.

Parameters:

Name Type Description Default
items iterable

Input items in their nearly sorted order.

required
order callable

Function returning a comparable ordering key.

required
lookahead int

Maximum number of records retained before the oldest ordered item is emitted. 0 preserves physical order.

required

Attributes:

Name Type Description
late_count int

Number of irreparably late items discarded.

__init__(items, order, lookahead)

Initialize the bounded ordering iterator.

__iter__()

Return this object as its own iterator.

__next__()

Return the next ordered item or raise StopIteration.