Implementation:Avhz RustQuant Quote
| Knowledge Sources | |
|---|---|
| Domains | Cashflow_Analysis, Quantitative_Finance |
| Last Updated | 2026-02-07 19:00 GMT |
Overview
Concrete tool for representing financial market quotes provided by the RustQuant library.
Description
The module defines a Quote trait and two implementing types for financial quote management. The Quote trait requires two methods: value() returning an Option<f64> (None when the quote has no value), and is_valid() returning a bool indicating whether the quote currently holds a value. The SimpleQuote struct wraps an Option<f64> and implements the trait directly: value() returns the inner option, and is_valid() returns true when the value is Some. It provides new() for construction, set_value() which updates the value and returns the difference between the new and old values (returning 0.0 when both are None or values are equal), and reset() which clears the value to None. A DerivedQuote<F> struct is also defined for quotes whose value is derived by applying a function (Fn(f64) -> f64) to another value, though its implementation is currently a stub.
Usage
Use these types when you need observable market quotes that can notify dependent calculations of value changes, such as in yield curve construction, option pricing, or any system where market data feeds into valuation models.
Code Reference
Source Location
- Repository: RustQuant
- File: crates/RustQuant_cashflows/src/quotes.rs
- Lines: 1-104
Signature
pub trait Quote {
fn value(&self) -> Option<f64>;
fn is_valid(&self) -> bool;
}
pub struct SimpleQuote {
value: Option<f64>,
}
impl SimpleQuote {
pub fn new(value: Option<f64>) -> Self;
pub fn set_value(&mut self, value: Option<f64>) -> f64;
pub fn reset(&mut self);
}
impl Quote for SimpleQuote { ... }
pub struct DerivedQuote<F>
where
F: Fn(f64) -> f64,
{
_value: Option<f64>,
_function: F,
}
Import
use RustQuant::cashflows::{Quote, SimpleQuote};
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| value | Option<f64> | Yes (for new()) | Initial quote value, or None for an uninitialized quote |
| value | Option<f64> | Yes (for set_value()) | New value to set; returns the difference from old value |
Outputs
| Name | Type | Description |
|---|---|---|
| Option<f64> | value() | The current quote value, or None if not set |
| bool | is_valid() | True if the quote has a value (i.e., value is Some) |
| f64 | set_value() | Difference between the new value and the old value |
Usage Examples
use RustQuant::cashflows::{Quote, SimpleQuote};
// Create a quote with an initial value
let mut quote = SimpleQuote::new(Some(10.0));
assert!(quote.is_valid());
assert_eq!(quote.value(), Some(10.0));
// Update the quote value
let diff = quote.set_value(Some(15.0));
assert_eq!(diff, 5.0);
assert_eq!(quote.value(), Some(15.0));
// Reset the quote
quote.reset();
assert!(!quote.is_valid());
assert_eq!(quote.value(), None);
// Create an uninitialized quote
let empty_quote = SimpleQuote::new(None);
assert!(!empty_quote.is_valid());