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 signed sell size must not read as free), a negative λ estimate is clamped to 0 (noise, never a subsidy), and non-finite inputs are neutral. -
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
-