Implementation:Avhz RustQuant Finite Difference Pricer
| Knowledge Sources | |
|---|---|
| Domains | Option_Pricing, Quantitative_Finance |
| Last Updated | 2026-02-07 19:00 GMT |
Overview
Concrete tool for pricing European and American options using finite difference methods (explicit, implicit, and Crank-Nicolson schemes) provided by the RustQuant library.
Description
This module implements the FiniteDifferencePricer struct which prices vanilla call and put options -- both European and American exercise styles -- using three finite difference (FD) discretization schemes on a log-price grid:
- Explicit method: Forward-stepping with a tridiagonal matrix-vector multiply.
- Implicit method: Backward-stepping by inverting the tridiagonal system.
- Crank-Nicolson method: A half-step combination of explicit and implicit schemes for improved accuracy.
The grid is constructed in log-price space centered at ln(S) spanning +/-5 standard deviations. American early exercise is handled via a time-stop comparison at each step. The module supports TypeFlag (Call/Put) and ExerciseFlag (European/American) from the option flags module. Boundary conditions are computed for calls at the upper price boundary and puts at the lower price boundary. Date handling uses the time crate with the Actual/365.25 day count convention.
Usage
Use when numerical PDE-based pricing is required, especially for American options where no closed-form solution exists, or for validating analytical prices with a grid-based approach.
Code Reference
Source Location
- Repository: RustQuant
- File: crates/RustQuant_instruments/src/options/finite_difference_pricer.rs
- Lines: 1-789
Signature
pub struct FiniteDifferencePricer {
pub initial_price: f64,
pub strike_price: f64,
pub risk_free_rate: f64,
pub volatility: f64,
pub evaluation_date: Option<Date>,
pub expiration_date: Date,
pub time_steps: u32,
pub price_steps: u32,
pub type_flag: TypeFlag,
pub exercise_flag: ExerciseFlag,
}
impl FiniteDifferencePricer {
pub fn new(
initial_price: f64,
strike_price: f64,
risk_free_rate: f64,
volatility: f64,
evaluation_date: Option<Date>,
expiration_date: Date,
time_steps: u32,
price_steps: u32,
type_flag: TypeFlag,
exercise_flag: ExerciseFlag,
) -> Self
pub fn explicit(&self) -> f64
pub fn implicit(&self) -> f64
pub fn crank_nicolson(&self) -> f64
}
Import
use RustQuant::instruments::{FiniteDifferencePricer, TypeFlag, ExerciseFlag};
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| initial_price | f64 | Yes | Spot price of the underlying (must be positive) |
| strike_price | f64 | Yes | Option strike price (must be positive) |
| risk_free_rate | f64 | Yes | Risk-free interest rate (must be positive) |
| volatility | f64 | Yes | Volatility of the underlying (must be positive) |
| evaluation_date | Option<Date> | No | Valuation date; defaults to today |
| expiration_date | Date | Yes | Option expiration date |
| time_steps | u32 | Yes | Number of time steps in the FD grid (must be positive) |
| price_steps | u32 | Yes | Number of price steps in the FD grid (must be positive) |
| type_flag | TypeFlag | Yes | Call or Put |
| exercise_flag | ExerciseFlag | Yes | European or American exercise style |
Outputs
| Name | Type | Description |
|---|---|---|
| price | f64 | The finite-difference option price |
Usage Examples
use RustQuant::instruments::{FiniteDifferencePricer, TypeFlag, ExerciseFlag};
use time::macros::date;
let pricer = FiniteDifferencePricer::new(
10.0, // initial_price
10.0, // strike_price
0.05, // risk_free_rate
0.1, // volatility
Some(date!(2024 - 01 - 01)), // evaluation_date
date!(2025 - 01 - 01), // expiration_date
10000, // time_steps
250, // price_steps
TypeFlag::Call,
ExerciseFlag::European { expiry: date!(2025 - 01 - 01) },
);
let price_explicit = pricer.explicit();
let price_implicit = pricer.implicit();
let price_cn = pricer.crank_nicolson();