Trait YieldCurve
pub trait YieldCurve<R: Scalar> {
// Required methods
fn reference_date(&self) -> NaiveDate;
fn discount(&self, date: NaiveDate) -> Result<R, CurveError>;
// Provided methods
fn log_discount(&self, date: NaiveDate) -> Result<R, CurveError> { ... }
fn discount_at_ordinal(&self, ordinal: i32) -> Result<R, CurveError> { ... }
fn log_discount_at_ordinal(&self, ordinal: i32) -> Result<R, CurveError> { ... }
fn rate_day_count(&self) -> DayCountFraction { ... }
fn zero_rate(&self, date: NaiveDate) -> Result<R, CurveError> { ... }
fn forward_rate(
&self,
start: NaiveDate,
end: NaiveDate,
) -> Result<R, CurveError> { ... }
}Expand description
What a pricer sees. Four methods, one mode, no AD vocabulary.
Required Methods§
fn reference_date(&self) -> NaiveDate
fn reference_date(&self) -> NaiveDate
The date at which the discount factor is 1.
fn discount(&self, date: NaiveDate) -> Result<R, CurveError>
fn discount(&self, date: NaiveDate) -> Result<R, CurveError>
The discount factor to date.
§Errors
CurveError::BeforeReference if date precedes the reference date.
Provided Methods§
fn log_discount(&self, date: NaiveDate) -> Result<R, CurveError>
fn log_discount(&self, date: NaiveDate) -> Result<R, CurveError>
The log discount factor to date.
The composition seam. Every stored family holds or derives its
curve in log space, and a composed curve is a sum of its parts’
logs: this method lets a composite add logs and exponentiate once,
rather than exponentiate each part and multiply — and lets the rate
defaults below read a log directly rather than ln an exp. Leaves
override it to answer from what they store; the default here serves a
family that genuinely only knows its discount factor.
§Errors
CurveError::BeforeReference if date precedes the reference date.
fn discount_at_ordinal(&self, ordinal: i32) -> Result<R, CurveError>
fn discount_at_ordinal(&self, ordinal: i32) -> Result<R, CurveError>
The discount factor to the proleptic-Gregorian day number ordinal.
The hot-path entry. A coupon stores its dates’ ordinals at build,
and the piecewise leaf answers this with one integer subtraction
against its stored reference ordinal instead of decoding two dates —
bit-identically, because both are differences in the same day
numbering. The default converts back to a date and answers through
discount: correct for any family, and the slow
path only for one that has not overridden it.
§Errors
CurveError::BeforeReference if ordinal precedes the reference
date’s, exactly as the date query reports it.
fn log_discount_at_ordinal(&self, ordinal: i32) -> Result<R, CurveError>
fn log_discount_at_ordinal(&self, ordinal: i32) -> Result<R, CurveError>
fn rate_day_count(&self) -> DayCountFraction
fn rate_day_count(&self) -> DayCountFraction
The day count this curve forms a rate under.
Not the measure it discounts on: a pillar here is a dated discount factor, so the curve is a function of dates and the year fractions it interpolates over are an internal parametrisation rather than anything the caller stated. Changing this moves no discount factor, and a family whose implementation moves one is wrong.
The measure becomes visible exactly where a rate is formed — the two readings below, and a family built from a rate, which answers from the convention it was given. ACT/365 fixed by default, which is what every family anchored to it before the measure could be stated.
fn zero_rate(&self, date: NaiveDate) -> Result<R, CurveError>
fn zero_rate(&self, date: NaiveDate) -> Result<R, CurveError>
The continuously-compounded zero rate to date.
Derived from log_discount by default, measured
under rate_day_count. A family that can
compute it more directly overrides.
§Errors
CurveError::BeforeReference if date precedes the reference date.
fn forward_rate(
&self,
start: NaiveDate,
end: NaiveDate,
) -> Result<R, CurveError>
fn forward_rate( &self, start: NaiveDate, end: NaiveDate, ) -> Result<R, CurveError>
The continuously-compounded forward rate between start and end.
Derived from log_discount by default, over the
span rate_day_count measures.
§Errors
CurveError::BeforeReference if either date precedes the reference date.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".