Class InternalizationEngine
java.lang.Object
com.quantfinlib.crb.InternalizationEngine
The internalize-or-route decision — the economics that justify a
central risk book's existence. Every internalized unit of flow saves
the street's spread AND market impact twice over (the client's
execution and the eventual hedge), so:
- Risk-REDUCING flow (opposite sign to the book's net) is internalized up to the offsetting inventory, and the client is given back a share of the saved spread as price improvement — the book was going to pay to shed that risk anyway;
- Risk-ADDING flow is warehoused (internalized without improvement) only while the post-trade inventory stays inside the warehouse limit — beyond that it routes out, because a warehouse limit that yields to one more trade is not a limit.
Flows and exposures are in the SAME factor units (currency
notional for EQ:/CCY: factors). Counters accumulate
for the internalizationRate() the desk reports. Sign
convention matches CentralRiskBook: the flow is what the book
ABSORBS if it internalizes. Deterministic, single-threaded.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordWhere one flow went, and what the client got for it. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondecide(double bookNet, double flow, double halfSpreadBps) Decides one flow against the book's current net on that factor.doubleFraction of decided notional the book kept (0 before any flow).doublevoidRestores counters written bywriteState(java.io.DataOutput).doublevoidwriteState(DataOutput out) Serializes the counters plus the configuration they were earned under.
-
Constructor Details
-
InternalizationEngine
public InternalizationEngine(double warehouseLimit, double improvementShare) - Parameters:
warehouseLimit- max |inventory| the book will hold on a factor after absorbing risk-adding flow, > 0improvementShare- fraction of the half spread returned to a risk-reducing client, in [0, 1]
-
-
Method Details
-
decide
Decides one flow against the book's current net on that factor.- Parameters:
bookNet- the book's net exposure on the factor (signed)flow- exposure change the book absorbs if it internalizes (signed, non-zero)halfSpreadBps- the street's half spread for this risk — what internalizing saves, > 0
-
internalizationRate
public double internalizationRate()Fraction of decided notional the book kept (0 before any flow). -
internalizedNotional
public double internalizedNotional() -
routedNotional
public double routedNotional() -
writeState
Serializes the counters plus the configuration they were earned under.- Throws:
IOException
-
readState
Restores counters written bywriteState(java.io.DataOutput). The configuration must MATCH: an internalization rate earned under one warehouse limit says nothing about a different one, so a mismatch throws rather than silently blending regimes.- Throws:
IOException
-