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§
Required Methods§
Provided Methods§
Sourcefn discount_rate(&self, _state: &[f64; N]) -> f64
fn discount_rate(&self, _state: &[f64; N]) -> f64
Optional discount rate at the given state. Default implementation returns 0.0.
Sourcefn constant_discount_rate(&self) -> Option<f64>
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).
Sourcefn apply_constraint(&self, _state: &[f64; N], value: f64) -> f64
fn apply_constraint(&self, _state: &[f64; N], value: f64) -> f64
Optional constraint application (e.g. for American options) Default implementation does nothing.
Sourcefn fill_rate_base(&self, _state: &[f64; N]) -> f64
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.
Sourcefn fill_rate_decay(&self) -> f64
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.
Sourcefn next_step(
&self,
current_state: &[f64; N],
dt: f64,
noise: &[f64; N],
) -> [f64; N]
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
Sourcefn next_step_controlled(
&self,
current_state: &[f64; N],
_control: &ControlOutput<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]
Simulates the next state for Coupled FBSDE exploration where dynamics depend on control.
Default implementation falls back to next_step (Decoupled).
Sourcefn is_diffusion_dimension(&self, _dim: usize) -> bool
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).
Sourcefn is_integer_dimension(&self, _dim: usize) -> bool
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).
Sourcefn transform_noise(&self, _state: &[f64; N], noise: &[f64; N]) -> [f64; N]
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.
Sourcefn gradient_step(&self, _dim: usize) -> f64
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".