Implementation:Avhz RustQuant Longstaff Schwartz
| Knowledge Sources | |
|---|---|
| Domains | Option_Pricing, Quantitative_Finance |
| Last Updated | 2026-02-07 19:00 GMT |
Overview
Concrete tool for pricing American options using the Longstaff-Schwartz least-squares Monte Carlo method provided by the RustQuant library.
Description
This module implements the Longstaff-Schwartz (2001) least-squares Monte Carlo (LSMC) algorithm for pricing American-style options via the LongstaffScwhartzPricer struct. The algorithm works by:
- Simulating terminal asset prices using a log-normal random walk (GBM discretization).
- Performing backward induction through time steps, generating intermediate prices via Brownian bridge interpolation.
- At each time step, identifying in-the-money paths and fitting a Laguerre polynomial regression (up to 5th order) via least-squares (QR decomposition from
nalgebra) to estimate continuation values. - Comparing immediate exercise payoff against estimated continuation value to determine the optimal exercise decision.
The pricer supports both calls and puts, with optional seeding for reproducibility. Date handling uses the Actual/365.25 day count convention.
Usage
Use when pricing American options where early exercise must be considered, and analytical solutions are unavailable. This is particularly useful for puts on non-dividend-paying stocks and other cases where the finite difference approach may be less convenient.
Code Reference
Source Location
- Repository: RustQuant
- File: crates/RustQuant_instruments/src/options/longstaff_schwartz.rs
- Lines: 1-466
Signature
pub struct LongstaffScwhartzPricer {
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 type_flag: TypeFlag,
pub num_simulations: u64,
pub seed: Option<u64>,
}
impl LongstaffScwhartzPricer {
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,
type_flag: TypeFlag,
num_simulations: u64,
seed: Option<u64>,
) -> Self
pub fn generate_price(&self) -> f64
}
Import
use RustQuant::instruments::{LongstaffScwhartzPricer, TypeFlag};
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 (must be after evaluation_date) |
| time_steps | u32 | Yes | Number of time steps for backward induction (must be positive) |
| type_flag | TypeFlag | Yes | Call or Put |
| num_simulations | u64 | Yes | Number of Monte Carlo simulation paths (must be positive) |
| seed | Option<u64> | No | Optional RNG seed for reproducibility |
Outputs
| Name | Type | Description |
|---|---|---|
| price | f64 | The estimated American option price |
Usage Examples
use RustQuant::instruments::{LongstaffScwhartzPricer, TypeFlag};
use time::macros::date;
let pricer = LongstaffScwhartzPricer::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
1000, // time_steps
TypeFlag::Put,
500, // num_simulations
Some(1234), // seed for reproducibility
);
let price = pricer.generate_price();