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], derivs: &StateDerivatives<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.

Source

pub 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

pub fn fill_rate_decay(&self) -> f64

The fill-rate decay parameter used for intensity-to-spread conversion.

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 ControlProblem<3> for BilateralHawkesOrderFlowImbalance

Source§

type Control = MarketMakingControl

The action type. For Merton this is a scalar portfolio fraction; for market making it is a pair of bid/ask intensities.
Source§

fn optimize( &self, _t: f64, state: &[f64; 3], derivs: &StateDerivatives<3>, ) -> Self::Control

Returns the control that maximizes the driver at (t, state).
Source§

fn running_reward( &self, _t: f64, _state: &[f64; 3], control: &Self::Control, ) -> f64

Returns the running reward f(t,x,u).
Source§

fn bsde_driver( &self, _t: f64, state: &[f64; 3], control: &Self::Control, _derivs: &StateDerivatives<3>, dt: f64, ) -> f64

Returns the backward driver consumed by the BSDE regression solver. Read more
Source§

fn generator( &self, _t: f64, state: &[f64; 3], _control: &Self::Control, derivs: &StateDerivatives<3>, ) -> f64

Returns the infinitesimal generator L^u V for the given control and derivative bundle.
Source§

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

Terminal value g(x) at the horizon.
Source§

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

Discount rate r(t,x). Defaults to zero.
Source§

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

Constant discount rate hint. Defaults to None (state dependent).
Source§

fn next_step( &self, _t: f64, state: &[f64; 3], dt: f64, noise: &[f64; 3], ) -> [f64; 3]

Advances the state one step under the optimal control at forward time t.
Source§

fn next_step_controlled( &self, _t: f64, state: &[f64; 3], control: &Self::Control, dt: f64, noise: &[f64; 3], ) -> [f64; 3]

Advances the state one step under an explicitly supplied control. Read more
Source§

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

Whether a dimension is driven by Brownian diffusion.
Source§

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

Physical finite-difference step for a dimension, used by mesh-free gradient stencils.
Source§

fn driver( &self, t: f64, state: &[f64; N], control: &Self::Control, derivs: &StateDerivatives<N>, ) -> f64

Returns the full HJB driver f(t,x,u) + L^u V. Read more
Source§

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

Optional pointwise constraint on the value, e.g. the early-exercise obstacle V >= payoff for an American option. Read more
Source§

fn is_reduced_value(&self) -> bool

Whether the value this problem solves is a reduced value. 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 PdeProblem<3> for BilateralHawkesOrderFlowImbalance

Source§

fn dimension_kind(&self, dim: usize) -> DimensionKind

Discretization kind for dim. Read more
Source§

fn transport( &self, _t: f64, state: &[f64; 3], control: &Self::Control, derivs: &StateDerivatives<3>, ) -> Transport<3>

Transport and local source for the given control and derivatives. Read more
Source§

fn jump_kernel( &self, _t: f64, _state: &[f64; N], _control: &Self::Control, _derivs: &StateDerivatives<N>, transport: &Transport<N>, ) -> JumpKernel<N>

Jump kernel for arbitrary-amplitude jump dimensions. 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 = !

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

fn try_from(value: U) -> Result<T, !>

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