Class InternalizationEngine

java.lang.Object
com.quantfinlib.crb.InternalizationEngine

public final class InternalizationEngine extends Object
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.

  • 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, > 0
      improvementShare - fraction of the half spread returned to a risk-reducing client, in [0, 1]
  • Method Details

    • decide

      public InternalizationEngine.Decision decide(double bookNet, double flow, double halfSpreadBps)
      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

      public void writeState(DataOutput out) throws IOException
      Serializes the counters plus the configuration they were earned under.
      Throws:
      IOException
    • readState

      public void readState(DataInput in) throws IOException
      Restores counters written by writeState(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