Skip to main content

BilateralHawkesOrderFlowImbalance

Struct BilateralHawkesOrderFlowImbalance 

Source
pub struct BilateralHawkesOrderFlowImbalance {
Show 13 fields pub gamma: f64, pub sigma: f64, pub kappa: f64, pub alpha: f64, pub beta: f64, pub mu: f64, pub eta_ofi: f64, pub lambda_step: f64, pub dq: f64, pub q_min: f64, pub q_max: f64, pub terminal_condition: TerminalCondition, pub terminal_liquidation_half_spread: Option<f64>,
}
Expand description

Bilateral Hawkes model with price-impact-driven adverse selection.

§State Space: [q, lambda_plus, lambda_minus]

dimsymboldescription
0qInventory level (integer, jump-controlled)
1lambda_plusBuy market-order intensity (ODE drift, no noise)
2lambda_minusSell market-order intensity (ODE drift, no noise)

§Dynamics

d(lambda+) = beta*(mu - lambda+) dt + alpha dN+ d(lambda-) = beta*(mu - lambda-) dt + alpha dN- dS = sigma dW + eta_ofi (dN+ - dN-)

Each buy market order (dN+) moves the mid price UP by eta_ofi; each sell market order (dN-) moves it DOWN by eta_ofi. The market maker accounts for this price impact when setting optimal spreads.

§Optimal Spreads Under Price Impact

Deriving the FOC from the CARA HJB with per-fill wealth effect (q±1)*eta_ofi gives:

$$ \delta_{bid}^* = \delta_{base} - \frac{\partial V}{\partial q} + (q+1)\eta_{OFI} $$ $$ \delta_{ask}^* = \delta_{base} + \frac{\partial V}{\partial q} - (q-1)\eta_{OFI} $$

Economic interpretation:

  • Long inventory (q > 0): ask narrows (selling into a rising price is favourable), bid widens (avoid accumulating more when sell MOs push price down).
  • Short inventory (q < 0): ask widens (avoid shorting further into a rising price), bid narrows (cover cheaply when sell MOs push price down).

Setting eta_ofi = 0 recovers the plain BilateralHawkes (BHK) model exactly.

In the simulation pass impact_factor = -eta_ofi to SimulatedDataSource so the price process matches the assumed dynamics dS = sigma dW + eta_ofi (dN+ - dN-).

§Hawkes Approximation

Same fluid (mean-field) approximation as BilateralHawkes:

$$ d(\lambda_+)/dt \approx \beta(\mu - \lambda_+) + \alpha \lambda_+ $$ $$ d(\lambda_-)/dt \approx \beta(\mu - \lambda_-) + \alpha \lambda_- $$

Fields§

§gamma: f64

Risk-aversion parameter.

§sigma: f64

Price volatility.

§kappa: f64

Fill-rate decay (Avellaneda-Stoikov kappa).

§alpha: f64

Jump size added to the excited side’s intensity.

§beta: f64

Mean-reversion speed.

§mu: f64

Baseline intensity (mean-reversion target).

§eta_ofi: f64

Price impact per fill event (eta_ofi in dS = sigmadW + eta_ofi(dN+ - dN-)). Higher eta_ofi = stronger q-dependent spread correction. Setting eta_ofi = 0 recovers the plain BilateralHawkes (BHK) model.

§lambda_step: f64

Grid step for both lambda+ and lambda- dimensions.

§dq: f64

Grid step for the inventory dimension.

§q_min: f64

Minimum inventory (lower hard boundary). Defaults to -infinity.

§q_max: f64

Maximum inventory (upper hard boundary). Defaults to +infinity.

§terminal_condition: TerminalCondition

Terminal condition for the value function at T. Defaults to Zero.

§terminal_liquidation_half_spread: Option<f64>

Optional terminal liquidation half-spread used when terminal_condition is LiquidationCost. If None, uses the AS base spread.

Implementations§

Source§

impl BilateralHawkesOrderFlowImbalance

Source

pub fn new( gamma: f64, sigma: f64, kappa: f64, alpha: f64, beta: f64, mu: f64, eta_ofi: f64, ) -> Self

Source

pub fn with_terminal_condition( self, terminal_condition: TerminalCondition, ) -> Self

Source

pub fn with_terminal_liquidation_half_spread(self, half_spread: f64) -> Self

Source

pub fn with_inventory_bounds(self, q_min: f64, q_max: f64) -> Self

Source

pub fn with_lambda_step(self, lambda_step: f64) -> Self

Source

pub fn with_dq(self, dq: f64) -> Self

Source

pub fn get_spreads(&self, state: &[f64; 3], grads: &Gradients<3>) -> (f64, f64)

Computes optimal bid/ask half-spreads with price-impact-driven inventory correction.

When eta_ofi > 0 each fill carries an adverse-selection wealth effect (q±1)*eta_ofi. The FOC on the CARA HJB gives: delta_bid = base_spread - dV/dq_fwd + (q+1)*eta_ofi delta_ask = base_spread + dV/dq_bwd - (q-1)*eta_ofi

Long inventory (q > 0): ask narrows (sell into rising price), bid widens. Short inventory (q < 0): ask widens (avoid adding short), bid narrows. eta_ofi = 0 recovers the plain BHK spread formula identically.

Trait Implementations§

Source§

impl Clone for BilateralHawkesOrderFlowImbalance

Source§

fn clone(&self) -> BilateralHawkesOrderFlowImbalance

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BilateralHawkesOrderFlowImbalance

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Model<3> for BilateralHawkesOrderFlowImbalance

Source§

fn next_step( &self, current_state: &[f64; 3], dt: f64, _noise: &[f64; 3], ) -> [f64; 3]

Forward step using the fluid (mean-field) drift.

Source§

fn next_step_controlled( &self, current_state: &[f64; 3], control: &ControlOutput<3>, dt: f64, noise: &[f64; 3], ) -> [f64; 3]

Coupled step: inventory jumps based on current fill probabilities.

Source§

fn is_diffusion_dimension(&self, _dim: usize) -> bool

Both intensity dimensions follow deterministic ODE drift with no Brownian noise.

Source§

fn fill_rate_base(&self, state: &[f64; 3]) -> f64

The base arrival intensity is state-dependent: returns the average of the buy/sell intensity states for intensity-to-spread conversion.

Source§

type Process = ()

The underlying stochastic process driving the continuous state dimensions. Set to () for models without a corresponding market_model process.
Source§

fn process(&self)

Returns the underlying stochastic process, if any.
Source§

fn optimize(&self, state: &[f64; 3], grads: &Gradients<3>) -> ControlOutput<3>

Given the current state and value function gradients ($\nabla V$), computations the optimal controls. Read more
Source§

fn terminal(&self, state: &[f64; 3]) -> f64

Computes the terminal value function $V(T, x)$ (Final Condition). Usually represents liquidation cost or final utility of wealth.
Source§

fn constant_discount_rate(&self) -> Option<f64>

Optimization hint: Returns Some(r) if the discount rate is constant across all states. Returns None if it depends on state. Default implementation returns None (safe fallback).
Source§

fn is_integer_dimension(&self, dim: usize) -> bool

Indicates if a dimension takes only integer values (e.g. inventory q). Controls BSDE initialization: integer dimensions are sampled discretely while continuous dimensions (even if non-diffusion) are sampled with uniform noise. Default: false (continuous).
Source§

fn gradient_step(&self, dim: usize) -> f64

Physical finite-difference step for each state dimension used by BSDE gradient stencils. Read more
Source§

fn fill_rate_decay(&self) -> f64

Order fill decay parameter $\kappa$ used for intensity-to-spread conversion. Defaults to 1.0 for non-market-making models. Override in market-making models.
Source§

fn discount_rate(&self, _state: &[f64; N]) -> f64

Optional discount rate at the given state. Default implementation returns 0.0.
Source§

fn apply_constraint(&self, _state: &[f64; N], value: f64) -> f64

Optional constraint application (e.g. for American options) Default implementation does nothing.
Source§

fn transform_noise(&self, _state: &[f64; N], noise: &[f64; N]) -> [f64; N]

Optional transform for standard normal samples before forward stepping. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V