pub enum Compounding {
Simple,
Continuous,
Periodic {
periods_per_year: u32,
},
}Expand description
Compounding convention for converting between discount factors and zero rates.
For time t > 0 and zero rate r:
| Variant | Discount factor | Inverse |
|---|---|---|
Simple | D = 1 / (1 + r*t) | r = (1/D - 1) / t |
Continuous | D = exp(-r*t) | r = -ln(D) / t |
Periodic { n } | D = (1 + r/n)^(-n*t) | r = n * (D^(-1/(n*t)) - 1) |
At t = 0 the discount factor is exactly 1 for any rate, and the
“rate implied by D = 1” is 0. All other queries with t = 0 are
errors.
Variants§
Simple
Simple interest: D = 1 / (1 + r * t).
Continuous
Continuously compounded: D = exp(-r * t).
Periodic
Periodic compounding with n periods per year.
Implementations§
Source§impl Compounding
impl Compounding
Sourcepub fn discount_from_rate(self, rate: f64, t: f64) -> Result<f64, TypeError>
pub fn discount_from_rate(self, rate: f64, t: f64) -> Result<f64, TypeError>
Returns the discount factor implied by a zero rate over time t.
§Errors
TypeError::NonFiniteifrateortis not finite.TypeError::NonPositiveRangeift < 0.TypeError::InvalidTenorifCompounding::Periodichasperiods_per_year == 0.
§Examples
use regit_curves::types::Compounding;
let d = Compounding::Continuous.discount_from_rate(0.05, 2.0).unwrap();
assert!((d - (-0.10_f64).exp()).abs() < 1e-15);Sourcepub fn rate_from_discount(self, discount: f64, t: f64) -> Result<f64, TypeError>
pub fn rate_from_discount(self, discount: f64, t: f64) -> Result<f64, TypeError>
Returns the zero rate implied by a discount factor over time t.
At t = 0 and discount = 1 the function returns 0.0. Any other
t = 0 query is rejected because the rate is undefined.
§Errors
TypeError::NonFiniteifdiscountortis not finite.TypeError::NonPositiveRangeift < 0, or ift == 0anddiscount != 1.0.TypeError::InvalidTenorifdiscount <= 0(the rate is undefined / infinite), or ifCompounding::Periodichasperiods_per_year == 0.
§Examples
use regit_curves::types::Compounding;
let r = Compounding::Continuous
.rate_from_discount((-0.10_f64).exp(), 2.0)
.unwrap();
assert!((r - 0.05).abs() < 1e-15);Trait Implementations§
Source§impl Clone for Compounding
impl Clone for Compounding
Source§fn clone(&self) -> Compounding
fn clone(&self) -> Compounding
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for Compounding
Source§impl Debug for Compounding
impl Debug for Compounding
impl Eq for Compounding
Source§impl Hash for Compounding
impl Hash for Compounding
Source§impl PartialEq for Compounding
impl PartialEq for Compounding
impl StructuralPartialEq for Compounding
Auto Trait Implementations§
impl Freeze for Compounding
impl RefUnwindSafe for Compounding
impl Send for Compounding
impl Sync for Compounding
impl Unpin for Compounding
impl UnsafeUnpin for Compounding
impl UnwindSafe for Compounding
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