Class KalmanBeta
java.lang.Object
com.quantfinlib.microstructure.KalmanBeta
Time-varying regression by Kalman filter — the pairs desk's upgrade
over a static OLS hedge ratio. The state
[α, β] follows a
random walk (relationships drift: index compositions change, business
mixes shift, a hedge ratio fitted on last year is stale by spring),
and each observation y = α + β·x + ε nudges the estimate by
exactly as much as its information content warrants:
state: [α, β]_t = [α, β]_{t-1} + noise(q)
observation: y_t = α_t + β_t·x_t + noise(r)
The knobs mean something. processNoise (q) is how fast you
believe the relationship drifts: 0 collapses to recursive least
squares (β converges and freezes), large q chases every tick.
observationNoise (r) is how noisy each print is. Their ratio
is what matters. betaVariance() is the filter's own
uncertainty; a hedge sized off a β the filter itself distrusts is a
position, not a hedge.
Pairs workflow: hedging.CointegrationTest (is there a
relationship?), then this class (what is the ratio now?), then
OrnsteinUhlenbeck on the resulting spread (how fast does it
revert?), then execution.SpreadExecutionAlgo (execute with the
legging cap). O(1) per observation, allocation-free after
construction, deterministic; research/warm lane.
-
Constructor Summary
ConstructorsConstructorDescriptionKalmanBeta(double initialBeta, double initialVariance, double processNoise, double observationNoise) -
Method Summary
Modifier and TypeMethodDescriptiondoublealpha()The current intercept estimate.doublebeta()The current hedge ratio estimate.doubleThe filter's own uncertainty about β — size hedges accordingly.longdoubleonObservation(double x, double y) One observation pair:y ≈ α + β·x.
-
Constructor Details
-
KalmanBeta
public KalmanBeta(double initialBeta, double initialVariance, double processNoise, double observationNoise) - Parameters:
initialBeta- starting hedge ratio (an OLS fit is a fine seed)initialVariance- how much to distrust the seed, > 0processNoise- per-step state drift variance q, ≥ 0 (0 = the relationship never drifts: RLS)observationNoise- per-observation noise variance r, > 0
-
-
Method Details
-
onObservation
public double onObservation(double x, double y) One observation pair:y ≈ α + β·x.- Returns:
- the innovation (observation minus prediction) — the filter's own surprise, useful as a spread signal
-
alpha
public double alpha()The current intercept estimate. -
beta
public double beta()The current hedge ratio estimate. -
betaVariance
public double betaVariance()The filter's own uncertainty about β — size hedges accordingly. -
observations
public long observations()
-