Function z_spread_on_curve
pub fn z_spread_on_curve<C: YieldCurve<f64>>(
bond: &FixedRateBond,
curve: &C,
price: f64,
basis: PriceBasis,
settlement: NaiveDate,
) -> Result<f64, SpreadSolveError>Expand description
The z-spread implied by a dirty price: the flat continuously-compounded
spread s for which Σ aᵢ·DF(tᵢ)·exp(−s·τᵢ) equals the quote.
A passive kernel. A spread is a quoted quantity read off a price, so this takes and returns plain numbers and the iterations record nothing — the same rule the callable OAS follows, and for the same reason: sixty bisection steps through an active view would tape sixty valuations whose derivatives nothing reads.
τ is measured by curves::discount::year_fraction,
which is the function FlatSpread
applies. That is not an implementation detail: it is what makes solving a
z-spread and pinning it as a security spread exact inverses rather than
agreeing to a tolerance. A spread that does not invert its own pin is a
number with no referent.
The curve’s discount factors are read once, before iterating: they do
not depend on the spread, so the loop is one exp per flow and no curve
queries at all.
§Errors
SpreadSolveError::Unbracketed when no spread in [−10%, 30%] reproduces
the price, SpreadSolveError::Unconverged on the iteration cap, and
SpreadSolveError::Curve from the discount queries.