Skip to main content

solver/numeric/bsde/
config.rs

1use crate::numeric::basis::{PolynomialBasis, PolynomialType};
2
3/// BSDE Solver Mode
4///
5/// Configures how the Forward-Backward Stochastic Differential Equation is solved.
6///
7/// * `Decoupled`: For systems where the Forward SDE (price dynamics) does NOT depend on the solution $Y_t$ (Value Function) or $Z_t$ (Control).
8///   This is the standard case for utility maximization where asset prices are exogenous.
9///   Solves backwards in one pass.
10/// * `Coupled`: For systems where asset dynamics depend on the control (e.g. Large Trader / Price Impact models).
11///   Requires Picard iteration to find a fixed point for $(X, Y, Z)$.
12pub enum BsdeMode {
13    Decoupled,
14    Coupled {
15        max_picard_iterations: usize,
16        tolerance: f64,
17        continuation_steps: usize, // Method of Continuation (0 or 1 = Off)
18    },
19}
20
21/// Polynomial Basis Functions for Regression
22///
23/// Used to approximate the conditional expectation $\mathbb{E}[Y_{t+1} | X_t]$ via Least Squares Monte Carlo.
24#[derive(Debug, Clone, Copy)]
25pub enum BasisFunctionType {
26    /// Standard polynomials: $1, x, x^2, \dots$
27    Power(usize),
28    /// Probabilists' Hermite polynomials: $He_n(x)$. Orthogonal wrt Gaussian measure. Best for Brownian Motion.
29    Hermite(usize),
30    /// Chebyshev polynomials (1st kind): $T_n(x)$. Minimax approximation on $[-1, 1]$.
31    Chebyshev(usize),
32    /// Laguerre polynomials: $L_n(x)$. Orthogonal for exponential weight $e^{-x}$ on $[0, \infty)$.
33    Laguerre(usize),
34}
35
36impl BasisFunctionType {
37    /// Converts the enum to the new `Basis` trait object (boxed) or specific struct.
38    pub fn to_basis<const N: usize>(&self) -> PolynomialBasis {
39        match self {
40            BasisFunctionType::Power(d) => PolynomialBasis::new(*d, PolynomialType::Power),
41            BasisFunctionType::Hermite(d) => PolynomialBasis::new(*d, PolynomialType::Hermite),
42            BasisFunctionType::Chebyshev(d) => PolynomialBasis::new(*d, PolynomialType::Chebyshev),
43            BasisFunctionType::Laguerre(d) => PolynomialBasis::new(*d, PolynomialType::Laguerre),
44        }
45    }
46}
47
48/// Initialization Strategy for the Forward SDE.
49#[derive(Debug, Clone, Copy, PartialEq)]
50pub enum InitializationMode {
51    /// Initialize all dimensions in a small local cloud: $x_{init} \pm \text{range}$.
52    Local(f64),
53    /// Initialize locally but on integer grid points for discrete dimensions:
54    /// * Diffusion dimensions: $x_{init} \pm \text{range}$.
55    /// * Discrete dimensions: Uniform integer grid $[x_{init} - range, x_{init} + range]$.
56    LocalDiscrete(f64),
57    /// Random Global State.
58    /// * Diffusion dimensions: $x_{init} \pm \text{local\_range}$.
59    /// * Discrete dimensions: Uniform integer grid $[-max, max]$.
60    GlobalDiscrete { local_range: f64, discrete_max: i32 },
61    /// Random Global State via Uniform Distribution.
62    /// * Diffusion dimensions: $x_{init} \pm \text{local\_range}$.
63    /// * Discrete dimensions: Uniform floating point distribution $[-max, max]$.
64    GlobalUniform { local_range: f64, uniform_max: f64 },
65}