pub struct LogLinearInterpolator { /* private fields */ }Expand description
Log-linear interpolation between data points.
Interpolates the natural logarithm of y values, then exponentiates the result. This is commonly used for discount factor interpolation as it:
- Guarantees positive interpolated values
- Produces piecewise constant forward rates
The interpolation formula is:
y(x) = exp(linear_interpolate(x, ln(y)))§Example
use convex_math::interpolation::{LogLinearInterpolator, Interpolator};
// Discount factors at different maturities
let times = vec![0.0, 1.0, 2.0, 3.0];
let discount_factors = vec![1.0, 0.97, 0.94, 0.91];
let interp = LogLinearInterpolator::new(times, discount_factors).unwrap();
let df = interp.interpolate(1.5).unwrap();
assert!(df > 0.0); // Always positiveImplementations§
Source§impl LogLinearInterpolator
impl LogLinearInterpolator
Sourcepub fn with_extrapolation(self) -> Self
pub fn with_extrapolation(self) -> Self
Enables extrapolation beyond the data range.
Trait Implementations§
Source§impl Clone for LogLinearInterpolator
impl Clone for LogLinearInterpolator
Source§fn clone(&self) -> LogLinearInterpolator
fn clone(&self) -> LogLinearInterpolator
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LogLinearInterpolator
impl Debug for LogLinearInterpolator
Source§impl Interpolator for LogLinearInterpolator
impl Interpolator for LogLinearInterpolator
Source§fn interpolate(&self, x: f64) -> MathResult<f64>
fn interpolate(&self, x: f64) -> MathResult<f64>
Returns the interpolated value at x.
Source§fn derivative(&self, x: f64) -> MathResult<f64>
fn derivative(&self, x: f64) -> MathResult<f64>
Returns the first derivative at x. Read more
Source§fn allows_extrapolation(&self) -> bool
fn allows_extrapolation(&self) -> bool
Returns true if extrapolation is allowed.
Auto Trait Implementations§
impl Freeze for LogLinearInterpolator
impl RefUnwindSafe for LogLinearInterpolator
impl Send for LogLinearInterpolator
impl Sync for LogLinearInterpolator
impl Unpin for LogLinearInterpolator
impl UnwindSafe for LogLinearInterpolator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.