Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Avhz RustQuant CIR Bond Pricing

From Leeroopedia


Knowledge Sources
Domains Fixed_Income, Quantitative_Finance
Last Updated 2026-02-07 19:00 GMT

Overview

Implements zero-coupon bond pricing under the Cox-Ingersoll-Ross (CIR) short-rate model, which incorporates mean reversion and a volatility term proportional to the square root of the short rate.

Description

The CoxIngersollRoss struct models the risk-neutral short rate dynamics according to the stochastic differential equation:

dr = a(b - r)dt + sigma * sqrt(r) * dW

where a is the speed of mean reversion, b is the long-term mean level, sigma is the diffusion coefficient, and r is the current short rate. The square-root diffusion term ensures that the standard deviation of rate changes increases as the short rate rises, and it prevents the rate from becoming negative (provided the Feller condition 2ab > sigma^2 is met).

The bond price is computed analytically using the closed-form CIR formula involving auxiliary functions A(t) and B(t) that depend on the model parameters and time to maturity. Time to maturity is computed from the evaluation date to the expiration date using the default day count convention.

Usage

Use this struct when you need to price a zero-coupon bond under the CIR interest rate model. It is appropriate for scenarios where you want mean-reverting rates with volatility that scales with the rate level.

Code Reference

Source Location

Signature

pub struct CoxIngersollRoss {
    a: f64,
    b: f64,
    r: f64,
    sigma: f64,
    pub evaluation_date: Option<Date>,
    pub expiration_date: Date,
}

impl Instrument for CoxIngersollRoss {
    fn price(&self) -> f64;
    fn error(&self) -> Option<f64>;
    fn valuation_date(&self) -> Date;
    fn instrument_type(&self) -> &'static str;
}

Import

use RustQuant::instruments::bonds::cox_ingersoll_ross::CoxIngersollRoss;

I/O Contract

Inputs

Name Type Required Description
a f64 Yes Speed of mean reversion
b f64 Yes Long-term mean level of the short rate
r f64 Yes Current short rate
sigma f64 Yes Diffusion coefficient (volatility)
evaluation_date Option<Date> No Valuation date; defaults to today if None
expiration_date Date Yes Maturity date of the zero-coupon bond

Outputs

Name Type Description
price() f64 The zero-coupon bond price under the CIR model (value between 0 and 1)
error() Option<f64> Always returns None (analytic solution, no error estimate)
valuation_date() Date Returns evaluation_date or today
instrument_type() &'static str Returns "Zero Coupon Bond"

Usage Examples

use RustQuant::instruments::bonds::cox_ingersoll_ross::CoxIngersollRoss;
use RustQuant::instruments::Instrument;
use RustQuant::time::today;

let expiry = today() + time::Duration::days(365);

let cir = CoxIngersollRoss {
    a: 0.3,
    b: 0.1,
    sigma: 0.03,
    r: 0.03,
    evaluation_date: None,
    expiration_date: expiry,
};

let bond_price = cir.price();
// Expected: approximately 0.9613

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment