convex-math
Mathematical utilities for the Convex fixed income analytics library.
Overview
convex-math provides numerical algorithms commonly used in fixed income calculations:
- Solvers: Root-finding algorithms for yield calculations
- Interpolation: Methods for yield curve interpolation
- Optimization: Function optimization for curve fitting
- Linear Algebra: Matrix operations for financial calculations
Features
Root-Finding Algorithms
use ;
// Newton-Raphson (requires derivative)
let f = ;
let df = ;
let result = newton_raphson.unwrap;
// result.root ≈ √2
// Brent's method (bracketing, no derivative needed)
let result = brent.unwrap;
// Bisection (simple but reliable)
let result = bisection.unwrap;
Interpolation
use ;
// Linear interpolation
let xs = vec!;
let ys = vec!;
let linear = new.unwrap;
let y = linear.interpolate.unwrap;
// Cubic spline (smoother)
let spline = new.unwrap;
let y = spline.interpolate.unwrap;
Linear Algebra
use ;
use ;
// Efficient tridiagonal solver (common in spline fitting)
let a = vec!; // Lower diagonal
let b = vec!; // Main diagonal
let c = vec!; // Upper diagonal
let d = vec!; // RHS
let x = solve_tridiagonal.unwrap;
// General linear system
let a = from_row_slice;
let b = from_vec;
let x = solve_linear_system.unwrap;
Performance
- Root-finding: Typically converges in < 10 iterations
- Interpolation: O(log n) lookup with binary search
- Tridiagonal solver: O(n) complexity
Installation
Add to your Cargo.toml:
[]
= "0.1"
License
This project is licensed under the MIT License - see the LICENSE file for details.