Skip to main content

Model

Trait Model 

Source
pub trait Model<const N: usize> {
    type Process;

Show 14 methods // Required methods fn process(&self) -> Self::Process; fn optimize( &self, state: &[f64; N], grads: &Gradients<N>, ) -> ControlOutput<N>; fn terminal(&self, state: &[f64; N]) -> f64; // Provided methods fn discount_rate(&self, _state: &[f64; N]) -> f64 { ... } fn constant_discount_rate(&self) -> Option<f64> { ... } fn apply_constraint(&self, _state: &[f64; N], value: f64) -> f64 { ... } fn fill_rate_base(&self, _state: &[f64; N]) -> f64 { ... } fn fill_rate_decay(&self) -> f64 { ... } fn next_step( &self, current_state: &[f64; N], dt: f64, noise: &[f64; N], ) -> [f64; N] { ... } fn next_step_controlled( &self, current_state: &[f64; N], _control: &ControlOutput<N>, dt: f64, noise: &[f64; N], ) -> [f64; N] { ... } fn is_diffusion_dimension(&self, _dim: usize) -> bool { ... } fn is_integer_dimension(&self, _dim: usize) -> bool { ... } fn transform_noise(&self, _state: &[f64; N], noise: &[f64; N]) -> [f64; N] { ... } fn gradient_step(&self, _dim: usize) -> f64 { ... }
}
Expand description

Interface for Optimal Control Models.

Defines the specific physics, market dynamics, and objective function of a financial model. Implementing this trait allows the model to be solved by any Solver.

Required Associated Types§

Source

type Process

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

Required Methods§

Source

fn process(&self) -> Self::Process

Returns the underlying stochastic process, if any.

Source

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

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

This is where the Hamiltonian optimization $\sup_{u} H(t, x, u, \nabla V)$ happens.

Source

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

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

Provided Methods§

Source

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

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

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 apply_constraint(&self, _state: &[f64; N], value: f64) -> f64

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

Source

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

Base order arrival rate $A$ used for intensity-to-spread conversion. May depend on the current state (e.g. Hawkes lambda). Defaults to 1.0.

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 next_step( &self, current_state: &[f64; N], dt: f64, noise: &[f64; N], ) -> [f64; N]

Simulates the next state for BSDE exploration. Default implementation is a simple random walk: x’ = x + sqrt(dt) * noise

Source

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

Simulates the next state for Coupled FBSDE exploration where dynamics depend on control. Default implementation falls back to next_step (Decoupled).

Source

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

Indicates if a dimension is driven by Brownian diffusion. If true, the BSDE backward step will skip the lambda_plus/minus drift term for this dimension (it is already handled by the forward simulation noise).

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 transform_noise(&self, _state: &[f64; N], noise: &[f64; N]) -> [f64; N]

Optional transform for standard normal samples before forward stepping.

This allows models to introduce cross-factor coupling (for example, correlated Brownian factors) while keeping the solver sampling path allocation unchanged.

Source

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

Physical finite-difference step for each state dimension used by BSDE gradient stencils.

Discrete jump dimensions should usually keep step 1.0. Continuous factors (for example variance or intensity) can override this with their natural grid/scale spacing.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§