Implementation:Avhz RustQuant CouponBond
| Knowledge Sources | |
|---|---|
| Domains | Fixed_Income, Quantitative_Finance |
| Last Updated | 2026-02-07 19:00 GMT |
Overview
Implements a coupon bond as a debt instrument that pays periodic interest coupons and returns the face value at maturity, modeled internally as a portfolio of zero-coupon bonds.
Description
The CouponBond struct represents a fixed-income instrument that makes regular coupon payments over its lifetime and repays the principal at maturity. The implementation provides two representations: CouponBond<C>, which is a full coupon bond parameterized by a calendar type for business day conventions, and CouponBond2, which explicitly models the bond as a portfolio of ZeroCouponBond instances stored in a BTreeMap keyed by payment date.
The CouponBond<C> struct holds all essential bond parameters including face value, coupon rate, coupon frequency, evaluation and expiration dates, a discount curve, and an optional currency. The construct_coupons method generates the coupon schedule by computing dates and amounts based on the frequency and coupon rate, including the final payment which combines the last coupon with the face value. Pricing is performed via the Instrument trait, which discounts each coupon cash flow using the provided discount curve and sums the present values.
Usage
Use this struct when you need to price a fixed-rate coupon bond given a discount curve. It is suitable for bonds with regular periodic coupon payments (e.g., semi-annual, quarterly) and supports customizable calendars and date rolling conventions.
Code Reference
Source Location
- Repository: RustQuant
- File: crates/RustQuant_instruments/src/bonds/coupon_bond.rs
- Lines: 1-241
Signature
pub struct CouponBond<C: Calendar> {
pub face_value: f64,
pub schedule: Schedule,
pub calendar: C,
pub evaluation_date: Date,
pub expiration_date: Date,
pub currency: Option<Currency>,
pub coupon_rate: f64,
pub coupon_frequency: Frequency,
pub settlement_convention: DateRollingConvention,
pub discount_curve: DiscountCurve<Date, C>,
pub coupons: BTreeMap<Date, f64>,
}
pub struct CouponBond2 {
pub coupons: BTreeMap<Date, ZeroCouponBond>,
}
impl<C: Calendar> CouponBond<C> {
pub fn construct_coupons(&mut self);
}
impl<C: Calendar> Instrument for CouponBond<C> {
fn price(&self) -> f64;
fn error(&self) -> Option<f64>;
fn valuation_date(&self) -> Date;
fn instrument_type(&self) -> &'static str;
}
impl CouponBond2 {
pub fn validate_dates(&self) -> bool;
}
Import
use RustQuant::instruments::bonds::coupon_bond::{CouponBond, CouponBond2};
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| face_value | f64 | Yes | The par value of the bond repaid at maturity |
| schedule | Schedule | Yes | Payment schedule for coupons |
| calendar | C (Calendar) | Yes | Calendar used for business day adjustments |
| evaluation_date | Date | Yes | The date the bond is being priced |
| expiration_date | Date | Yes | The maturity date of the bond |
| currency | Option<Currency> | No | The currency denomination of the bond |
| coupon_rate | f64 | Yes | The annual coupon rate (e.g. 0.05 for 5%) |
| coupon_frequency | Frequency | Yes | How often coupons are paid (e.g. SemiAnnually) |
| settlement_convention | DateRollingConvention | Yes | Convention for adjusting settlement dates |
| discount_curve | DiscountCurve<Date, C> | Yes | Yield curve used for discounting cash flows |
| coupons | BTreeMap<Date, f64> | Yes | Map of coupon dates to coupon amounts (populated by construct_coupons) |
Outputs
| Name | Type | Description |
|---|---|---|
| price() | f64 | The net present value of all coupon cash flows and face value |
| error() | Option<f64> | Always returns None (no error estimate available) |
| valuation_date() | Date | Returns the evaluation_date |
| instrument_type() | &'static str | Returns "Coupon Bond" |
| validate_dates() (CouponBond2) | bool | Returns true if all zero-coupon bonds share the same evaluation date |
Usage Examples
use RustQuant::instruments::bonds::coupon_bond::CouponBond;
use RustQuant::instruments::Instrument;
use std::collections::BTreeMap;
use time::Duration;
let today = today();
let mut bond = CouponBond {
evaluation_date: today,
expiration_date: today + Duration::days(365 * 2),
currency: Some(USD),
coupon_rate: 0.15,
coupon_frequency: Frequency::SemiAnnually,
settlement_convention: DateRollingConvention::Actual,
discount_curve: create_test_discount_curve(today),
face_value: 1000.0,
coupons: BTreeMap::new(),
// calendar and schedule fields also required
};
bond.construct_coupons();
let npv = bond.price();