| Crates.io | convex-bonds |
| lib.rs | convex-bonds |
| version | 0.11.1 |
| created_at | 2025-12-07 13:05:14.835434+00 |
| updated_at | 2026-01-07 07:06:19.805602+00 |
| description | Bond pricing and analytics for the Convex fixed income analytics library |
| homepage | |
| repository | https://github.com/sujitn/convex |
| max_upload_size | |
| id | 1971563 |
| size | 863,633 |
Bond pricing and analytics for the Convex fixed income analytics library.
convex-bonds provides comprehensive bond analysis:
use convex_bonds::prelude::*;
use convex_core::types::{Date, Currency, Frequency};
use rust_decimal_macros::dec;
let bond = FixedBondBuilder::new()
.isin("US912828Z229")
.coupon_rate(dec!(0.025)) // 2.5%
.maturity(Date::from_ymd(2030, 5, 15).unwrap())
.frequency(Frequency::SemiAnnual)
.currency(Currency::USD)
.day_count("ACT/ACT")
.build()
.unwrap();
use convex_bonds::pricing::BondPricer;
let settlement = Date::from_ymd(2025, 1, 15).unwrap();
// Price from yield
let result = BondPricer::price_from_yield(&bond, dec!(0.03), settlement).unwrap();
println!("Clean Price: {}", result.clean_price);
println!("Dirty Price: {}", result.dirty_price);
println!("Accrued: {}", result.accrued_interest);
// Calculate YTM from price
let ytm = BondPricer::yield_to_maturity(&bond, result.clean_price, settlement).unwrap();
use convex_bonds::cashflows::CashFlowGenerator;
let schedule = CashFlowGenerator::generate(&bond, settlement).unwrap();
for cf in schedule.iter() {
println!("{}: {} ({})", cf.date(), cf.amount(), cf.cf_type());
}
let accrued = CashFlowGenerator::accrued_interest(&bond, settlement).unwrap();
Use business day calendars for settlement and payment date adjustments:
use convex_core::calendars::{SIFMACalendar, Calendar, BusinessDayConvention};
let cal = SIFMACalendar::new();
// Calculate settlement date (T+1)
let trade_date = Date::from_ymd(2025, 1, 15).unwrap();
let settlement = cal.settlement_date(trade_date, 1);
// Adjust payment dates
let adjusted = cal.adjust(payment_date, BusinessDayConvention::ModifiedFollowing).unwrap();
use convex_bonds::risk::RiskCalculator;
let metrics = RiskCalculator::calculate(&bond, dec!(0.03), settlement).unwrap();
println!("Macaulay Duration: {}", metrics.duration.macaulay);
println!("Modified Duration: {}", metrics.duration.modified);
println!("Convexity: {}", metrics.convexity);
println!("DV01: {}", metrics.dv01);
// Estimate price change for 50bp yield increase
let price_change = RiskCalculator::estimate_price_change(
&metrics,
result.clean_price,
dec!(0.005),
);
Standard fixed coupon bond with:
Discount bond with:
Add to your Cargo.toml:
[dependencies]
convex-bonds = "0.1"
This project is licensed under the MIT License - see the LICENSE file for details.