Expand description
Multi-dimensional optimization for model calibration, one algorithm
per file. This is the fitting layer for every parametric model —
Heston today (equity::heston::calibrate),
SABR / Nelson-Siegel or any other least-squares fit tomorrow — so the
machinery lives in one place, like solvers
does for 1-D root finding.
Gradient-based (analytic gradient optional — central finite differences fill in when absent):
- [
steepest_descent]: robust baseline, linear convergence; - [
conjugate_gradient]: nonlinear CG (Polak-Ribiere with restarts); - [
bfgs]: quasi-Newton with the inverse-Hessian update — the default choice for smooth unconstrained problems; - [
levenberg_marquardt]: for least squaresmin sum r_i(x)^2specifically — the standard calibration workhorse.
Gradient-free:
- [
nelder_mead]: the simplex method, for noisy or non-smooth objectives; - [
differential_evolution]: seeded, bounded global search for multimodal landscapes (e.g. a cold-start calibration before a gradient polish).
Every algorithm can be called directly, or through the pluggable
minimize with a Method enum and a Problem description:
use rustyqlib::core::optimization::{minimize, Method, OptimConfig, Problem};
let rosenbrock = |x: &[f64]| {
(1.0 - x[0]).powi(2) + 100.0 * (x[1] - x[0] * x[0]).powi(2)
};
let problem = Problem::scalar(&rosenbrock, vec![-1.2, 1.0]);
let fit = minimize(&OptimConfig::default(), Method::Bfgs, &problem).unwrap();
assert!((fit.x[0] - 1.0).abs() < 1e-5 && (fit.x[1] - 1.0).abs() < 1e-5);Re-exports§
pub use bfgs::bfgs;pub use conjugate_gradient::conjugate_gradient;pub use differential_evolution::differential_evolution;pub use levenberg_marquardt::levenberg_marquardt;pub use nelder_mead::nelder_mead;pub use steepest_descent::steepest_descent;
Modules§
- bfgs
- BFGS quasi-Newton: builds an inverse-Hessian approximation from gradient differences, giving superlinear convergence on smooth problems. The default choice for unconstrained smooth calibration.
- conjugate_
gradient - Nonlinear conjugate gradient (Polak-Ribiere+): steepest descent’s cost per iteration with far better search directions on ill- conditioned valleys, no matrix storage.
- differential_
evolution - Differential evolution (DE/rand/1/bin): seeded, bounded global search. The tool for multimodal calibration landscapes — find the basin globally, then polish with BFGS or Levenberg-Marquardt.
- levenberg_
marquardt - Levenberg-Marquardt: the standard damped Gauss-Newton method for
nonlinear least squares
min sum r_i(x)^2— the calibration workhorse (Heston, SABR, Nelson-Siegel, curve and surface fits). - nelder_
mead - Nelder-Mead simplex: gradient-free local search by reflecting,
expanding and contracting a simplex of
n + 1points. The tool for noisy or non-smooth objectives where gradients mislead. - steepest_
descent - Steepest descent: follow
-gradientwith a backtracking line search. Linear convergence — the robust baseline, and the reference the fancier methods are tested against.
Structs§
- Optim
Config - Optimizer configuration: convergence tolerance and iteration cap.
- Optim
Result - Result of an optimization run.
- Problem
- An optimization problem: a scalar objective or a residual vector (least squares), whatever derivatives are available, a start, and optional bounds.