Shared Rust kernels
catalogue/bonds
All modules · quoted at commit 9e1884369a67 of DnaCalc/DnaCalc. Comments are the source's own.
basis · 8 lines · calc-func/src/catalogue/bonds.rs on GitHub/// The optional basis at `index`: `None` when the call does not reach it.
fn basis(site: &Site<'_>, a: &[CalcValue], index: usize) -> Step<Option<f64>> {
if index < a.len() {
num(site, a, index).map(Some)
} else {
Ok(None)
}
}
Used by 15 functions.
or · 4 lines · calc-func/src/catalogue/bonds.rs on GitHub/// An optional argument at `index`, or `default` when it is omitted.
fn or(site: &Site<'_>, a: &[CalcValue], index: usize, default: f64) -> Step<f64> {
if given(a, index) { num(site, a, index) } else { Ok(default) }
}
Used by 8 functions.
bill_arguments · 9 lines · calc-func/src/catalogue/bonds.rs on GitHub/// The bill functions admit and validate each date before reading the next scalar.
fn bill_arguments(site: &Site<'_>, a: &[CalcValue], sv: &EvalServices<'_>) -> Step<[f64; 3]> {
required_number(&a[0])?;
let settlement = super::kit::checked_date_serial(date_1900(site, a, 0, sv)?)?;
required_number(&a[1])?;
let maturity = super::kit::checked_date_serial(date_1900(site, a, 1, sv)?)?;
let rate = super::kit::num_without_logical(site, a, 2)?;
Ok([settlement, maturity, rate])
}
Used by 3 functions.
yield_date · 7 lines · calc-func/src/catalogue/bonds.rs on GitHub/// The yield entries admit each calendar serial before the next argument.
/// Fn8 conflicts retain negative/beyond-calendar NUM ahead of later errors;
/// zero and the fictitious1900 day still reach the existing bond kernel.
fn yield_date(site: &Site<'_>, a: &[CalcValue], index: usize, sv: &EvalServices<'_>) -> Step<f64> {
required_number(&a[index])?;
super::kit::checked_date_serial(date_1900(site, a, index, sv)?)
}
Used by 2 functions.
bond_out · 6 lines · calc-func/src/catalogue/bonds.rs on GitHubfn bond_out(site: &Site<'_>, result: Result<f64, bond::BondCoreEvalError>) -> Step<CalcValue> {
match result {
Ok(n) => site.number(n),
Err(error) => fail(bond::map_bond_core_error_to_ws(&error)),
}
}
Used by 9 functions.
bill_out · 6 lines · calc-func/src/catalogue/bonds.rs on GitHubfn bill_out(site: &Site<'_>, result: Result<f64, bill::DiscountBillYearfracEvalError>) -> Step<CalcValue> {
match result {
Ok(n) => site.number(n),
Err(error) => fail(bill::map_discount_bill_yearfrac_error_to_ws(&error)),
}
}
Used by 7 functions.
odd_out · 6 lines · calc-func/src/catalogue/bonds.rs on GitHubfn odd_out(site: &Site<'_>, result: Result<f64, odd::OddBondEvalError>) -> Step<CalcValue> {
match result {
Ok(n) => site.number(n),
Err(error) => fail(odd::map_odd_bond_error_to_ws(&error)),
}
}
Used by 4 functions.
coupon_out · 6 lines · calc-func/src/catalogue/bonds.rs on GitHubfn coupon_out(site: &Site<'_>, result: Result<f64, WorksheetErrorCode>) -> Step<CalcValue> {
match result {
Ok(n) => site.number(n),
Err(code) => fail(code),
}
}
Used by 4 functions.
date_out · 16 lines · calc-func/src/catalogue/bonds.rs on GitHub/// A 1900-system serial the kernel returned as a date, in the call's date system: before
/// 1 January 1904 is #NUM! in the 1904 system.
fn date_out(site: &Site<'_>, sv: &EvalServices<'_>, result: Result<f64, WorksheetErrorCode>) -> Step<CalcValue> {
let serial = match result {
Ok(serial) => serial,
Err(code) => return fail(code),
};
let Some(environment) = sv.environment() else {
return Err(site.not_modelled(None));
};
match environment.date_system {
DateSystem::System1900 => site.number(serial),
DateSystem::System1904 if serial >= OFFSET_1904 => site.number(serial - OFFSET_1904),
DateSystem::System1904 => fail(WorksheetErrorCode::Num),
}
}
Used by 2 functions.
coupon_args · 17 lines · calc-func/src/catalogue/bonds.rs on GitHub/// A COUP function: its settlement and maturity dates, frequency and basis. The dates are checked
/// before the frequency and basis are read: a settlement that is no date or on or after maturity
/// is #NUM! whatever they hold (Excel 16.0.20430, 2026-10-25, dc-6au: `=COUPDAYBS(1,1,#REF!)`,
/// `=COUPDAYBS(1,1,2,#REF!)`, `=COUPDAYBS(-1,1,#REF!)` and `=COUPDAYBS(2,1,"a")` are #NUM!, while
/// `=COUPDAYBS(1,2,#REF!)` is #REF! and `=COUPDAYBS(1,2,"a")` #VALUE!; the six COUP functions
/// alike).
fn coupon_args(
site: &Site<'_>,
a: &[CalcValue],
sv: &EvalServices<'_>,
) -> Step<(f64, f64, f64, Option<f64>)> {
let (settlement, maturity) = (date_1900(site, a, 0, sv)?, date_1900(site, a, 1, sv)?);
if let Err(code) = coupon::check_coupon_dates(settlement, maturity) {
return fail(code);
}
Ok((settlement, maturity, num(site, a, 2)?, basis(site, a, 3)?))
}
Used by 6 functions.