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 Vasicek 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 Vasicek's short-rate model, a mean-reverting Ornstein-Uhlenbeck process with constant coefficients.

Description

The Vasicek struct models the risk-neutral short rate dynamics according to:

dr(t) = k[theta - r(t)]dt + sigma * dW(t), r(0) = r0

where k is the speed of mean reversion, theta is the long-term mean level, sigma is the constant diffusion coefficient, and r0 is the initial short rate. Unlike the CIR model, Vasicek uses constant volatility, which means rates can theoretically become negative.

The bond price is computed analytically using the closed-form solution involving functions A(tau) and B(tau) where tau is the time to maturity. B(tau) = (1 - exp(-k * tau)) / k captures the mean-reversion effect, and A(tau) incorporates the long-run drift and variance terms. The final price is A(tau) * exp(-B(tau) * r0). Time to maturity is calculated 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 Vasicek interest rate model. It is appropriate for simple mean-reverting rate scenarios where constant volatility is an acceptable assumption.

Code Reference

Source Location

Signature

pub struct Vasicek {
    r0: f64,
    k: f64,
    theta: f64,
    sigma: f64,
    pub evaluation_date: Option<Date>,
    pub expiration_date: Date,
}

impl Instrument for Vasicek {
    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::vasicek::Vasicek;

I/O Contract

Inputs

Name Type Required Description
r0 f64 Yes Initial short rate r(0)
k f64 Yes Speed of mean reversion
theta f64 Yes Long-term mean level of the short rate
sigma f64 Yes Constant 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 Vasicek 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::vasicek::Vasicek;
use RustQuant::instruments::Instrument;
use RustQuant::time::today;

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

let vasicek = Vasicek {
    r0: 0.03,
    k: 0.3,
    theta: 0.1,
    sigma: 0.03,
    evaluation_date: None,
    expiration_date: expiry_date,
};

let bond_price = vasicek.price();
// Expected: approximately 0.9615

Related Pages

Page Connections

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