Skip to main content

YieldCurve

Struct YieldCurve 

Source
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

Source

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.

Source

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

Source

pub fn flat(reference: Date, rate: f64, day_count: DayCountConvention) -> Self

A curve with one rate for every maturity — the compatible special case.

Source

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.

Source

pub fn reference_date(&self) -> Date

Source

pub fn day_count(&self) -> DayCountConvention

Source

pub fn nodes(&self) -> &[(f64, f64)]

Source

pub fn time_to(&self, date: Date) -> Result<f64, ValuationContextError>

Years from the reference date to date, under the curve’s own day count.

Source

pub fn zero_rate(&self, t: f64) -> Result<f64, ValuationContextError>

Continuously compounded zero rate for maturity t, in years.

Source

pub fn discount_factor_at(&self, t: f64) -> Result<f64, ValuationContextError>

Discount factor for maturity t, in years: exp(-z(t) * t).

Source

pub fn discount_factor(&self, date: Date) -> Result<f64, ValuationContextError>

Discount factor for a calendar date.

Source

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.

Source

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

Source§

fn clone(&self) -> YieldCurve

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for YieldCurve

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for YieldCurve

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for YieldCurve

Source§

fn eq(&self, other: &YieldCurve) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for YieldCurve

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for YieldCurve

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.