Class KylesLambda
Δp = λ·q + noise, and λ (price per unit of signed volume)
is the market's depth read off its own behavior. Where
MarketImpactModel parameterizes impact (square-root law with
calibrated constants), this class runs the streaming through-origin
regression λ = E[q·Δp] / E[q²] on time-decayed moments. The
regression-through-origin form is standard here because both the signed
flow and the mid change are zero-mean at these horizons.
Feed one onSample(double, double) per aggregation window (a trade, a bar, a
decision interval): the mid change over the window and the signed volume
that traded in it (buy-aggressor positive; TradeClassifier
supplies the sign when the feed doesn't). impactBps(double, double) then prices
a contemplated child order in the units
execution.BenchmarkExecutor.MarketState.impactBps expects,
closing the last MarketState input that lacked a live producer. A noisy
negative λ estimate is clamped to zero impact there: "the market pays
you to trade" is an estimation artifact, and feeding it to the executor
would accelerate the schedule on garbage. lambda() stays raw for
diagnostics.
Gap discipline: non-finite inputs are skipped whole; the moments seed
from the first valid sample. Zero allocation per event, single writer,
one instance per symbol. Persistable via persist.Checkpoint —
depth is a slowly-moving property worth carrying across the
overnight.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleimpactBps(double quantity, double mid) The estimated impact of tradingquantitynow, in basis points ofmid, the live producer forMarketState.impactBps.doublelambda()The learned λ: price change per unit of signed volume.voidonSample(double midChange, double signedVolume) One aggregation window: the mid change over the window and the signed volume traded in it (+ = buyer-initiated).voidRestores the moments.longsamples()voidwriteState(DataOutput out) Persists the learned depth moments — seepersist.Checkpoint.
-
Constructor Details
-
KylesLambda
public KylesLambda(double alpha) - Parameters:
alpha- EWMA weight per sample, e.g. 0.02 (≈ 50-sample memory)
-
KylesLambda
public KylesLambda()2% sample weight.
-
-
Method Details
-
onSample
public void onSample(double midChange, double signedVolume) One aggregation window: the mid change over the window and the signed volume traded in it (+ = buyer-initiated). Non-finite or volume-free windows are skipped — no flow, no impact information. -
lambda
public double lambda()The learned λ: price change per unit of signed volume. Raw — can be negative while the estimate is noise. 0 until any flow is observed. -
impactBps
public double impactBps(double quantity, double mid) The estimated impact of tradingquantitynow, in basis points ofmid, the live producer forMarketState.impactBps. The sign of the quantity is ignored (impact is a cost in both directions), a negative λ estimate is clamped to 0 (noise, never a subsidy), and non-finite inputs are neutral.Units and aggregation. λ is estimated from
onSample(double, double)windows as price change per unit of net signed volume over one aggregation window (Kyle 1985, Econometrica 53(6); Hasbrouck 2007, ch. 5). Pricing a single child order with it assumes the child is the window's entire net flow: a child that is 10% of the window's flow is charged as if it moved the whole window. Pass the net quantity you expect to trade over one window of the same length as the one used for estimation (for example the parent order's slice per window), not an individual fill, and keepquantityin the same share units as the signed volume fed toonSample(double, double). -
samples
public long samples() -
writeState
Persists the learned depth moments — seepersist.Checkpoint.- Throws:
IOException
-
readState
Restores the moments. Throws on a version mismatch.- Throws:
IOException
-