pub struct FlatForward { /* private fields */ }Expand description
Flat forward interpolation for zero rate curves.
Interpolates zero rates such that forward rates are constant (flat) between pillar points. This produces a step-function forward curve.
§Example
use convex_math::interpolation::{FlatForward, Interpolator};
// Zero rates at 1Y, 2Y, 5Y, 10Y
let tenors = vec![1.0, 2.0, 5.0, 10.0];
let zero_rates = vec![0.02, 0.025, 0.03, 0.035];
let interp = FlatForward::new(tenors, zero_rates).unwrap();
// Interpolate at 3Y - forward rate is flat between 2Y and 5Y
let rate_3y = interp.interpolate(3.0).unwrap();Implementations§
Source§impl FlatForward
impl FlatForward
Sourcepub fn new(tenors: Vec<f64>, zero_rates: Vec<f64>) -> MathResult<Self>
pub fn new(tenors: Vec<f64>, zero_rates: Vec<f64>) -> MathResult<Self>
Creates a new flat forward interpolator from zero rates.
§Arguments
tenors- Time points in years (must be strictly increasing, > 0)zero_rates- Zero rates at each tenor (as decimals, e.g., 0.05 for 5%)
§Errors
Returns an error if:
- Fewer than 2 points are provided
- Tenors and zero_rates have different lengths
- Tenors are not strictly increasing
- Any tenor is <= 0
Sourcepub fn with_origin(tenors: Vec<f64>, zero_rates: Vec<f64>) -> MathResult<Self>
pub fn with_origin(tenors: Vec<f64>, zero_rates: Vec<f64>) -> MathResult<Self>
Creates a flat forward interpolator with an initial point at t=0.
This variant allows interpolation from t=0 by assuming the first zero rate extends back to the origin.
§Arguments
tenors- Time points in years (must be strictly increasing, >= 0)zero_rates- Zero rates at each tenor
Sourcepub fn with_extrapolation(self) -> Self
pub fn with_extrapolation(self) -> Self
Enables extrapolation beyond the data range.
When extrapolating:
- Below first tenor: uses first forward rate
- Above last tenor: uses last forward rate (flat forward extension)
Sourcepub fn forward_rate(&self, t: f64) -> MathResult<f64>
pub fn forward_rate(&self, t: f64) -> MathResult<f64>
Returns the forward rate at tenor t.
Since forward rates are flat between pillars, this returns the constant forward rate for the segment containing t.
Sourcepub fn zero_rates(&self) -> &[f64]
pub fn zero_rates(&self) -> &[f64]
Returns the zero rates.
Sourcepub fn forward_rates_vec(&self) -> &[f64]
pub fn forward_rates_vec(&self) -> &[f64]
Returns the pre-computed forward rates.
Trait Implementations§
Source§impl Clone for FlatForward
impl Clone for FlatForward
Source§fn clone(&self) -> FlatForward
fn clone(&self) -> FlatForward
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 FlatForward
impl Debug for FlatForward
Source§impl Interpolator for FlatForward
impl Interpolator for FlatForward
Source§fn interpolate(&self, t: f64) -> MathResult<f64>
fn interpolate(&self, t: f64) -> MathResult<f64>
Returns the interpolated value at x.
Source§fn derivative(&self, t: f64) -> MathResult<f64>
fn derivative(&self, t: 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 FlatForward
impl RefUnwindSafe for FlatForward
impl Send for FlatForward
impl Sync for FlatForward
impl Unpin for FlatForward
impl UnwindSafe for FlatForward
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.