pub struct YieldCurve { /* private fields */ }Expand description
A term structure of continuously compounded zero rates.
Between nodes the zero rate is linear in time; outside them it is held flat at the first respectively last node’s rate. Flat extrapolation is a convention, not a derivation — it is stated here rather than left implicit, because the alternative (continuing the slope) produces nonsensical discount factors a few years past the last node.
Continuously compounded zero rates are the representation because they stay well behaved when
rates are negative: the discount factor exp(-z * t) is positive for every real z, and a
flat curve is exactly the single-node case, so the constant-rate results this crate produced
before remain reproducible.
Implementations§
Source§impl YieldCurve
impl YieldCurve
Sourcepub fn bootstrap(
reference: Date,
instruments: &[CalibrationInstrument],
day_count: DayCountConvention,
) -> Result<Self, ValuationContextError>
pub fn bootstrap( reference: Date, instruments: &[CalibrationInstrument], day_count: DayCountConvention, ) -> Result<Self, ValuationContextError>
Builds a curve that reprices every given instrument.
Instruments are taken in order of maturity, each fixing one node. A zero rate fixes its node directly. A par swap is solved for: the zero rate at its maturity is chosen so that the curve — including the interpolation between the already fixed nodes and this one — values the swap at par. Solving against the interpolation actually used is what makes the result self-consistent; fixing nodes by a closed formula and interpolating afterwards would leave the intermediate payment dates mispriced.
Fails when instruments share a maturity, when one matures at or before the reference date,
or when a swap has no solution in the searched range of -50% to +100%.
The result is a plain YieldCurve: once built, nothing distinguishes it from one given
by hand, and the same flat extrapolation applies beyond the last instrument.
Sourcepub fn par_swap_rate(
&self,
maturity: Date,
frequency: u32,
) -> Result<f64, ValuationContextError>
pub fn par_swap_rate( &self, maturity: Date, frequency: u32, ) -> Result<f64, ValuationContextError>
The fixed rate that would make a swap of this maturity and frequency worth nothing on this curve — the curve’s own view of where that swap trades.
Repricing the instruments a curve was built from is how a bootstrap is checked, so this is deliberately public rather than hidden in a test.
Source§impl YieldCurve
impl YieldCurve
Sourcepub fn flat(reference: Date, rate: f64, day_count: DayCountConvention) -> Self
pub fn flat(reference: Date, rate: f64, day_count: DayCountConvention) -> Self
A curve with one rate for every maturity — the compatible special case.
Sourcepub fn from_zero_rates(
reference: Date,
nodes: Vec<(f64, f64)>,
day_count: DayCountConvention,
) -> Result<Self, ValuationContextError>
pub fn from_zero_rates( reference: Date, nodes: Vec<(f64, f64)>, day_count: DayCountConvention, ) -> Result<Self, ValuationContextError>
A curve through the given (time, zero rate) nodes.
Times are years from reference and must be finite, non-negative and strictly ascending;
rates must be finite. At least one node is required.
pub fn reference_date(&self) -> Date
pub fn day_count(&self) -> DayCountConvention
pub fn nodes(&self) -> &[(f64, f64)]
Sourcepub fn time_to(&self, date: Date) -> Result<f64, ValuationContextError>
pub fn time_to(&self, date: Date) -> Result<f64, ValuationContextError>
Years from the reference date to date, under the curve’s own day count.
Sourcepub fn zero_rate(&self, t: f64) -> Result<f64, ValuationContextError>
pub fn zero_rate(&self, t: f64) -> Result<f64, ValuationContextError>
Continuously compounded zero rate for maturity t, in years.
Sourcepub fn discount_factor_at(&self, t: f64) -> Result<f64, ValuationContextError>
pub fn discount_factor_at(&self, t: f64) -> Result<f64, ValuationContextError>
Discount factor for maturity t, in years: exp(-z(t) * t).
Sourcepub fn discount_factor(&self, date: Date) -> Result<f64, ValuationContextError>
pub fn discount_factor(&self, date: Date) -> Result<f64, ValuationContextError>
Discount factor for a calendar date.
Sourcepub fn shifted(&self, delta: f64) -> Self
pub fn shifted(&self, delta: f64) -> Self
The same curve with every zero rate shifted by delta, in absolute rate units — a
parallel shift. 0.0001 is one basis point.
Parallel is the only shape offered here: a twist or a steepening needs a statement about which part of the curve moves how, and that belongs to whoever has that view.
Sourcepub fn forward_rate(
&self,
t1: f64,
t2: f64,
) -> Result<f64, ValuationContextError>
pub fn forward_rate( &self, t1: f64, t2: f64, ) -> Result<f64, ValuationContextError>
Continuously compounded forward rate covering t1..t2, from the same term structure:
(z(t2) * t2 - z(t1) * t1) / (t2 - t1).
Trait Implementations§
Source§impl Clone for YieldCurve
impl Clone for YieldCurve
Source§fn clone(&self) -> YieldCurve
fn clone(&self) -> YieldCurve
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more