Implementation:Avhz RustQuant Binomial Backend
| Knowledge Sources | |
|---|---|
| Domains | Option_Pricing, Quantitative_Finance |
| Last Updated | 2026-02-07 19:00 GMT |
Overview
Concrete tool for pricing options using the Cox-Ross-Rubinstein binomial tree method provided by the RustQuant library.
Description
This module implements the BinomialOption struct with the Cox-Ross-Rubinstein (CRR) binomial tree pricing model, adapted from Haug's Complete Guide to Option Pricing Formulas. The CRR model constructs a recombining binomial tree where the up factor is u = exp(v * sqrt(dt)) and the down factor is d = 1/u. The risk-neutral probability is p = (exp(b * dt) - d) / (u - d) where b = r - q is the cost of carry.
The price_CoxRossRubinstein() method supports:
- European and American exercise styles via the
ExerciseFlagenum. - Output selection via a string flag:
"p"for price,"d"for delta,"g"for gamma, and"t"for theta. - The Greeks are extracted from the tree at the appropriate early nodes (j=1 for delta, j=2 for gamma and theta).
Usage
Use when pricing options with a binomial tree approach, especially for American-style options where early exercise needs to be evaluated at each node.
Code Reference
Source Location
- Repository: RustQuant
- File: crates/RustQuant_instruments/src/backends/binomial.rs
- Lines: 1-172
Signature
#[derive(Debug, Clone, Copy)]
pub struct BinomialOption {
initial_price: f64,
strike_price: f64,
time_to_expiry: f64,
risk_free_rate: f64,
dividend_yield: f64,
volatility: f64,
}
impl BinomialOption {
#[must_use]
pub fn price_CoxRossRubinstein(
&self,
output_flag: &str, // "p", "d", "g", or "t"
ame_eur_flag: ExerciseFlag, // American or European
call_put_flag: TypeFlag, // Call or Put
n: usize, // Height of the binomial tree
) -> f64
}
Import
use RustQuant::instruments::{BinomialOption, ExerciseFlag, TypeFlag};
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| initial_price | f64 | Yes | Initial underlying price (S) |
| strike_price | f64 | Yes | Option strike price (K) |
| time_to_expiry | f64 | Yes | Time to expiration in years (T) |
| risk_free_rate | f64 | Yes | Risk-free interest rate (r) |
| dividend_yield | f64 | Yes | Continuous dividend yield (q) |
| volatility | f64 | Yes | Volatility of the underlying (v) |
| output_flag | &str | Yes | Output selection: "p" (price), "d" (delta), "g" (gamma), "t" (theta) |
| ame_eur_flag | ExerciseFlag | Yes | American or European exercise style |
| call_put_flag | TypeFlag | Yes | Call or Put |
| n | usize | Yes | Number of steps in the binomial tree |
Outputs
| Name | Type | Description |
|---|---|---|
| result | f64 | The requested output: option price, delta, gamma, or theta |
Usage Examples
use RustQuant::instruments::{BinomialOption, ExerciseFlag, TypeFlag};
let option = BinomialOption {
initial_price: 100.0,
strike_price: 95.0,
time_to_expiry: 0.5,
risk_free_rate: 0.08,
dividend_yield: 0.0,
volatility: 0.3,
};
// Price an American call with 100-step tree
let call_price = option.price_CoxRossRubinstein(
"p",
ExerciseFlag::American,
TypeFlag::Call,
100,
);
// Get delta of a European put
let put_delta = option.price_CoxRossRubinstein(
"d",
ExerciseFlag::European,
TypeFlag::Put,
100,
);