Implementation:Avhz RustQuant AnalyticOptionPricer new
| Knowledge Sources | |
|---|---|
| Domains | Derivatives, Option_Pricing |
| Last Updated | 2026-02-07 20:00 GMT |
Overview
Concrete tool for creating a generic analytic option pricing engine provided by the RustQuant instruments crate.
Description
AnalyticOptionPricer<O, M> is a generic struct parameterized by an option type O and a model type M. It stores the option and model, then provides pricing and Greek methods that are specialized via Rust's monomorphization. When combined with EuropeanVanillaOption and a GBSM model, the macro european_vanilla_option_gbsm! generates all price and Greek methods automatically.
Usage
Import this struct after creating both an option contract and a pricing model. Construct the pricer with new(option, model), then call price(), delta(), report(), and other Greek methods.
Code Reference
Source Location
- Repository: RustQuant
- File: crates/RustQuant_instruments/src/analytic_option_pricer.rs
- Lines: L16-49
Signature
#[derive(Debug, derive_builder::Builder)]
pub struct AnalyticOptionPricer<O, M> {
pub option: O,
pub model: M,
}
impl<O, M> AnalyticOptionPricer<O, M> {
pub fn new(option: O, model: M) -> Self
pub fn option(&self) -> &O
pub fn model(&self) -> &M
pub fn set_option(&mut self, option: O)
pub fn set_model(&mut self, model: M)
}
Import
use RustQuant::instruments::AnalyticOptionPricer;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| option | O (e.g. EuropeanVanillaOption) | Yes | The option contract to price |
| model | M (e.g. BlackScholes73) | Yes | The pricing model with market parameters |
Outputs
| Name | Type | Description |
|---|---|---|
| return | AnalyticOptionPricer<O, M> | A pricer combining option and model, ready for price/Greek computation |
Usage Examples
Full Pricing Example
use RustQuant::instruments::{
AnalyticOptionPricer, BlackScholes73,
EuropeanVanillaOption, TypeFlag,
};
use time::macros::date;
// 1. Define the option
let option = EuropeanVanillaOption::new(
100.0,
date!(2025 - 12 - 31),
TypeFlag::Call,
);
// 2. Define the model
let model = BlackScholes73::new(100.0, 0.05, 0.20);
// 3. Create the pricer
let pricer = AnalyticOptionPricer::new(option, model);
// 4. Compute price and Greeks
let price = pricer.price();
let delta = pricer.delta();
let gamma = pricer.gamma();
// 5. Print full report
pricer.report();
Model Comparison
use RustQuant::instruments::{
AnalyticOptionPricer, BlackScholes73, Merton73,
EuropeanVanillaOption, TypeFlag,
};
use time::macros::date;
let option = EuropeanVanillaOption::new(100.0, date!(2025 - 12 - 31), TypeFlag::Call);
// Compare BS73 vs Merton73
let bs_pricer = AnalyticOptionPricer::new(option, BlackScholes73::new(100.0, 0.05, 0.20));
let merton_pricer = AnalyticOptionPricer::new(option, Merton73::new(100.0, 0.05, 0.02, 0.20));
println!("BS73 price: {}", bs_pricer.price());
println!("Merton73 price: {}", merton_pricer.price());