Implementation:Avhz RustQuant NelsonSiegelSvensson
| Knowledge Sources | |
|---|---|
| Domains | Stochastic_Processes, Quantitative_Finance |
| Last Updated | 2026-02-07 19:00 GMT |
Overview
Concrete implementation of the Nelson-Siegel-Svensson (1994) yield curve model provided by the RustQuant library, implementing the CurveModel trait.
Description
The Nelson-Siegel-Svensson (NSS) model extends the Nelson-Siegel model by adding a second hump term for greater flexibility in fitting yield curves. The forward rate at maturity tau is:
f(tau) = beta0 + beta1 * e^(-tau/lambda1) + beta2 * (tau/lambda1) * e^(-tau/lambda1) + beta3 * (tau/lambda2) * e^(-tau/lambda2)
The spot rate is derived by integrating the forward rate. The model implements the CurveModel trait, providing forward_rate(), spot_rate(), and discount_factor() methods.
Key parameters:
- beta0 (f64) -- Long-term level
- beta1 (f64) -- Short-term slope factor
- beta2 (f64) -- First curvature/hump factor
- beta3 (f64) -- Second curvature/hump factor
- lambda1 (f64) -- First decay parameter
- lambda2 (f64) -- Second decay parameter
Usage
Use this model for yield curve fitting and interpolation when the standard Nelson-Siegel model lacks flexibility (e.g., when the yield curve has a double hump). The NSS model is widely used by central banks (including the ECB and Bundesbank) for estimating term structures.
Code Reference
Source Location
- Repository: RustQuant
- File: crates/RustQuant_stochastics/src/nelson_siegel_svensson.rs
- Lines: 1-141
Signature
#[derive(Clone, Copy, Debug, PartialEq, Default)]
pub struct NelsonSiegelSvensson {
pub beta0: f64,
pub beta1: f64,
pub beta2: f64,
pub beta3: f64,
pub lambda1: f64,
pub lambda2: f64,
}
impl NelsonSiegelSvensson {
pub const fn new(
beta0: f64, beta1: f64, beta2: f64,
beta3: f64, lambda1: f64, lambda2: f64,
) -> Self
}
impl CurveModel for NelsonSiegelSvensson {
fn forward_rate(&self, date: Date) -> f64
fn spot_rate(&self, date: Date) -> f64
fn discount_factor(&self, date: Date) -> f64
}
Import
use RustQuant::stochastics::NelsonSiegelSvensson;
use RustQuant::stochastics::CurveModel;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| beta0 | f64 | Yes | Long-term level (asymptotic rate) |
| beta1 | f64 | Yes | Short-term slope factor |
| beta2 | f64 | Yes | First curvature/hump factor |
| beta3 | f64 | Yes | Second curvature/hump factor |
| lambda1 | f64 | Yes | First decay parameter |
| lambda2 | f64 | Yes | Second decay parameter |
Outputs
| Name | Type | Description |
|---|---|---|
| forward_rate() | f64 | Instantaneous forward rate for a given future date |
| spot_rate() | f64 | Spot (zero-coupon) rate for a given future date |
| discount_factor() | f64 | Discount factor from today to the given future date, computed as exp(-spot_rate * tau / 100) |
Usage Examples
use RustQuant::stochastics::NelsonSiegelSvensson;
use RustQuant::stochastics::CurveModel;
use time::Duration;
// Create an NSS model
let nss = NelsonSiegelSvensson::new(0.0806, -0.0031, -0.0625, -0.0198, 1.58, 0.15);
// Compute rates for dates in the future
let today = time::OffsetDateTime::now_utc().date();
let dates: Vec<time::Date> = (2..365 * 30)
.map(|i| today + Duration::days(i))
.collect();
// Forward curve
let forward_curve: Vec<f64> = dates.iter().map(|d| nss.forward_rate(*d)).collect();
// Discount curve
let discount_curve: Vec<f64> = dates.iter().map(|d| nss.discount_factor(*d)).collect();