Principle:Avhz RustQuant Instrument Abstraction
| Knowledge Sources | |
|---|---|
| Domains | Financial_Instruments, Software_Architecture |
| Last Updated | 2026-02-07 21:00 GMT |
Overview
A generic Instrument trait that defines the common interface for all financial instruments, providing methods for pricing (net present value), error estimation, valuation date, and instrument type identification.
Description
Instrument Abstraction is the foundational design principle in RustQuant's instrument hierarchy. The Instrument trait establishes a uniform contract that all financial instruments must satisfy, enabling polymorphic handling of diverse instrument types through a single interface.
The trait defines four required methods:
- price() returns the net present value (NPV) of the instrument as an
f64. This is the primary valuation method that every instrument must implement. - error() returns an
Option<f64>representing the estimation error on the NPV, if the pricing engine can provide one. For example, a Monte Carlo pricing engine can report a standard error, while an analytic pricer may returnNone. - valuation_date() returns the
time::Dateat which the NPV is calculated. For most instruments this is the trade date, but for exotic products it might be the exercise date. - instrument_type() returns a static string identifying the kind of instrument.
This trait is implemented by concrete types throughout the library, including Currency (which returns a price of 1.0), bonds, options, and other derivative products.
Usage
Use the Instrument trait when building generic pricing pipelines, portfolio aggregation systems, or any component that needs to operate on financial instruments without knowing their specific type. Implement the trait for new instrument types to integrate them into the existing pricing infrastructure.
Theoretical Basis
The Instrument trait reflects the standard quantitative finance concept that any financial instrument can be valued at a point in time to produce a net present value. The NPV represents the discounted expected value of all future cash flows. The optional error field accommodates both analytic pricing methods (which produce exact values) and numerical methods (which produce estimates with associated uncertainty).
In mathematical terms, for an instrument with future cash flows at times :
where is the discount factor at time .