Class QueuePositionEstimator
marketdata.L3BookBuilder needs to track position
exactly. With only aggregated level sizes you can't see individual orders,
so this estimator maintains a probabilistic band on where a passive order
sits, updated with the standard assumptions:
- On join — you rest at the back: shares-ahead = the level's current displayed size;
- Executions at your level — trades hit the front (price-time priority), so they reduce shares-ahead one-for-one;
- Cancels at your level — the hard part: a decrease in level
size that isn't a trade is a cancel, and it could be ahead of you
or behind. The literature's workable assumption is pro-rata:
a cancel removes shares-ahead in proportion to the fraction of the
queue that is ahead of you. That gives an unbiased estimate without
L3 — the
aheadfield is the expected value, andfillProbability(double)turns it into a fill likelihood viaQueueModel.
One passive order per instance (cheap — make one per working child).
Feed it the level's size changes split into the trade part and the total
part; it infers cancels as the residual. Feed ordering contract:
report each trade via onTrade(long) BEFORE the depth update that
reflects it, and give onLevelResize(long) sizes net of trades already
reported — otherwise the same execution is counted once as a trade and
again as a cancel, and shares-ahead falls twice per fill. Zero
allocation, single writer.
Cross-asset: applies to any price-time-priority level — equity
exchange books and FX ECN/matching books alike (sizes are just longs; an
FX "share" is a unit of base currency). It does NOT apply to FX LP quote
streams, which have no queues — that side is fx.LpRouter's
last-look world.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanactive()voidclose()Order left the book (filled/cancelled).doublefillProbability(double expectedTradedQty) Fill probability over a horizon in whichexpectedTradedQtyshares are expected to execute at this level —QueueModelapplied to the estimated position.voidjoin(long levelSize, long ownQty) Join the back of a level currently displayinglevelSizeshares (before our order is added).voidonLevelResize(long newLevelSize) The level's displayed size changed tonewLevelSizefor a reason other than a trade — i.e. cancels (net of any adds behind us).voidonTrade(long tradedQty) A trade executed at our level: it consumedtradedQtyfrom the front, so shares-ahead drops by that much (clamped at 0 — once the front reaches us we start filling).longownQty()doubleQueue progress since joining: 0 right afterjoin(long, long), 1 when the whole queue that was ahead of us has drained.doubleExpected shares ahead of our order right now.
-
Constructor Details
-
QueuePositionEstimator
public QueuePositionEstimator()
-
-
Method Details
-
join
public void join(long levelSize, long ownQty) Join the back of a level currently displayinglevelSizeshares (before our order is added). -
onTrade
public void onTrade(long tradedQty) A trade executed at our level: it consumedtradedQtyfrom the front, so shares-ahead drops by that much (clamped at 0 — once the front reaches us we start filling). -
onLevelResize
public void onLevelResize(long newLevelSize) The level's displayed size changed tonewLevelSizefor a reason other than a trade — i.e. cancels (net of any adds behind us). The removed quantity is attributed pro-rata: the fraction of the queue ahead of us isahead / (levelSize − ownQty), so that fraction of the cancel came from ahead. -
fillProbability
public double fillProbability(double expectedTradedQty) Fill probability over a horizon in whichexpectedTradedQtyshares are expected to execute at this level —QueueModelapplied to the estimated position. -
queueProgress
public double queueProgress()Queue progress since joining: 0 right afterjoin(long, long), 1 when the whole queue that was ahead of us has drained. Measured against the shares-ahead AT JOIN — the only meaningful baseline. -
active
public boolean active() -
ownQty
public long ownQty() -
close
public void close()Order left the book (filled/cancelled).
-