Principle:Avhz RustQuant Cashflow Analysis
| Knowledge Sources | |
|---|---|
| Domains | Fixed_Income, Financial_Instruments |
| Last Updated | 2026-02-07 21:00 GMT |
Overview
Cashflow analysis provides the building blocks for modeling financial payments, computing net present values, and aggregating sequences of cashflows into legs for instrument pricing.
Description
Cashflow analysis in RustQuant is built on three core abstractions: the Cashflow struct, the Leg struct, and the Quote trait.
A Cashflow represents a single monetary payment occurring on a specific date. It stores an amount (f64) and a date (Date). The struct supports arithmetic operations including addition, subtraction, multiplication by a scalar, division by a scalar, and negation. Addition and subtraction of cashflows require matching dates, enforced by runtime assertions. The key financial method is npv(discount_rate), which computes the net present value by multiplying the cashflow amount by a discount factor.
A Leg is a sequence of cashflows, representing one side of a financial instrument (e.g., the fixed leg or floating leg of an interest rate swap). The Leg struct provides:
npv(discount_rate): computes the total NPV by summing the discounted values of all constituent cashflowsstart_date()andend_date(): determine the temporal bounds of the legis_active(current_date): checks whether the leg spans the given dateadd_cashflow(): dynamically appends a cashflow to the sequence
A Quote is a trait defining a market observable value. The SimpleQuote implementation wraps an optional f64 value and provides methods for getting, setting, resetting, and validating the value. The set_value method returns the difference between old and new values, facilitating change detection. A DerivedQuote type allows computing quote values from a transformation function.
Usage
Use cashflow analysis when constructing the payment schedules of bonds, swaps, loans, or other fixed-income instruments. Legs are used to represent each side of a swap or the coupon stream of a bond. Quotes represent market prices, yields, or rates that feed into pricing models.
Theoretical Basis
The Net Present Value of a single cashflow is:
where is the cashflow amount and is the discount factor at time .
The NPV of a leg (sequence of cashflows) is the sum of individual discounted cashflows:
Cashflows on the same date can be combined additively, which is the mathematical basis for netting payments in swap valuation. The date-matching constraint ensures that cashflow aggregation is only performed between payments with identical settlement dates.