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 CurveModel Trait

From Leeroopedia


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

Overview

Trait definition for curve models provided by the RustQuant library.

Description

The CurveModel trait defines the interface for yield curve models in RustQuant. Any struct implementing this trait must provide methods for computing forward rates, spot rates, and discount factors given a date. This trait is implemented by yield curve models such as Nelson-Siegel-Svensson.

The trait requires three methods:

  • forward_rate -- Returns the instantaneous forward rate for a given date
  • spot_rate -- Returns the spot (zero-coupon) rate for a given date
  • discount_factor -- Returns the discount factor for a given date

Usage

Implement this trait when creating new yield curve models. Use it as a generic interface to abstract over different curve parameterizations (e.g., Nelson-Siegel, Nelson-Siegel-Svensson, or custom models).

Code Reference

Source Location

Signature

pub trait CurveModel {
    /// Returns the forward rate for a given date.
    fn forward_rate(&self, date: time::Date) -> f64;

    /// Returns the spot rate for a given date.
    fn spot_rate(&self, date: time::Date) -> f64;

    /// Returns the discount factor for a given date.
    fn discount_factor(&self, date: time::Date) -> f64;
}

Import

use RustQuant::stochastics::CurveModel;

I/O Contract

Inputs

Name Type Required Description
date time::Date Yes The target date for rate/factor computation

Outputs

Name Type Description
forward_rate() f64 The instantaneous forward rate at the given date
spot_rate() f64 The spot (zero-coupon) rate for the given date
discount_factor() f64 The discount factor from today to the given date

Usage Examples

use RustQuant::stochastics::CurveModel;
use RustQuant::stochastics::NelsonSiegelSvensson;
use time::Duration;

// Create a Nelson-Siegel-Svensson model implementing CurveModel
let nss = NelsonSiegelSvensson::new(0.0806, -0.0031, -0.0625, -0.0198, 1.58, 0.15);

// Use the CurveModel trait methods
let future_date = time::OffsetDateTime::now_utc().date() + Duration::days(365);
let fwd_rate = nss.forward_rate(future_date);
let spot = nss.spot_rate(future_date);
let df = nss.discount_factor(future_date);

Related Pages

Page Connections

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