pub struct Bootstrap {
pub reference_date: Date,
pub daycount: Daycount,
pub config: BootstrapConfig,
}Expand description
Sequential iterative bootstrap engine.
Constructs a DiscountCurve from a list of Instrument quotes by
driving each instrument’s residual to zero against the in-progress curve.
See the module-level documentation for the algorithm.
§Examples
use regit_curves::bootstrap::{Bootstrap, BootstrapConfig};
use regit_curves::instruments::{Deposit, Instrument};
use regit_curves::interpolation::Interpolation;
use regit_curves::types::{Date, Daycount};
let reference = Date::from_ymd(2024, 1, 2).unwrap();
let dep1 = Deposit::new(
reference,
Date::from_ymd(2024, 4, 2).unwrap(),
0.05,
Daycount::Act360,
)
.unwrap();
let dep2 = Deposit::new(
reference,
Date::from_ymd(2024, 7, 2).unwrap(),
0.05,
Daycount::Act360,
)
.unwrap();
let instruments = [Instrument::Deposit(dep1), Instrument::Deposit(dep2)];
let bootstrap = Bootstrap::new(reference, Daycount::Act360);
let curve = bootstrap
.build(&instruments, Interpolation::LogLinear)
.unwrap();
assert_eq!(curve.reference_date(), reference);Fields§
§reference_date: DateCurve anchor / reference date.
daycount: DaycountDay-count convention for the curve’s t-axis.
config: BootstrapConfigSolver configuration.
Implementations§
Source§impl Bootstrap
impl Bootstrap
Sourcepub fn new(reference_date: Date, daycount: Daycount) -> Self
pub fn new(reference_date: Date, daycount: Daycount) -> Self
Constructs a bootstrap engine with BootstrapConfig::default.
§Examples
use regit_curves::bootstrap::Bootstrap;
use regit_curves::types::{Date, Daycount};
let reference = Date::from_ymd(2024, 1, 2).unwrap();
let bs = Bootstrap::new(reference, Daycount::Act360);
assert_eq!(bs.reference_date, reference);
assert_eq!(bs.daycount, Daycount::Act360);Sourcepub fn with_config(self, config: BootstrapConfig) -> Self
pub fn with_config(self, config: BootstrapConfig) -> Self
Returns the bootstrap engine with the supplied configuration.
§Examples
use regit_curves::bootstrap::{Bootstrap, BootstrapConfig};
use regit_curves::types::{Date, Daycount};
let reference = Date::from_ymd(2024, 1, 2).unwrap();
let cfg = BootstrapConfig {
tolerance: 1e-10,
..BootstrapConfig::default()
};
let bs = Bootstrap::new(reference, Daycount::Act360).with_config(cfg);
assert!((bs.config.tolerance - 1e-10).abs() < 1e-18);Sourcepub fn build(
&self,
instruments: &[Instrument],
method: Interpolation,
) -> Result<DiscountCurve, BootstrapError>
pub fn build( &self, instruments: &[Instrument], method: Interpolation, ) -> Result<DiscountCurve, BootstrapError>
Builds a DiscountCurve that re-prices every instrument in
instruments to within BootstrapConfig::tolerance.
Instruments must be ordered by Instrument::pillar, strictly
increasing. The pillar of every instrument must lie strictly after
Bootstrap::reference_date.
§Errors
BootstrapError::InvalidInstrumentifinstrumentsis empty, or if any pillar is on or before the reference date.BootstrapError::NonIncreasingAnchorif pillars are not strictly increasing.BootstrapError::NoBracketif no sign change can be found in the discount-factor search interval for a leg, even after widening.BootstrapError::LegDidNotConvergeif Brent fails to converge, or if the outer iteration fails to converge withinBootstrapConfig::iter_maxpasses.BootstrapError::Curveif the final curve construction rejects the bootstrapped knots (should not happen given the validation above).BootstrapError::Typeif a day-count query fails.
§Examples
use regit_curves::bootstrap::Bootstrap;
use regit_curves::instruments::{Deposit, Instrument};
use regit_curves::interpolation::Interpolation;
use regit_curves::types::{Date, Daycount};
let reference = Date::from_ymd(2024, 1, 2).unwrap();
let dep = Deposit::new(
reference,
Date::from_ymd(2024, 4, 2).unwrap(),
0.05,
Daycount::Act360,
)
.unwrap();
let curve = Bootstrap::new(reference, Daycount::Act360)
.build(&[Instrument::Deposit(dep)], Interpolation::LogLinear)
.unwrap();
assert!(curve.discounts().len() == 2);Trait Implementations§
impl Copy for Bootstrap
impl StructuralPartialEq for Bootstrap
Auto Trait Implementations§
impl Freeze for Bootstrap
impl RefUnwindSafe for Bootstrap
impl Send for Bootstrap
impl Sync for Bootstrap
impl Unpin for Bootstrap
impl UnsafeUnpin for Bootstrap
impl UnwindSafe for Bootstrap
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