pub struct CoxRossRubinsteinVanillaEngine { /* private fields */ }Expand description
Prices European and American vanilla contracts with a flat-rate CRR tree.
Returns node delta/gamma and completes other requested Greeks numerically.
Values own their settings; shared instances support concurrent pricing.
See Self::price for an example.
Prices a supported vanilla contract.
See Self::price for an example.
§Errors
Returns Error::UnsupportedOperation for nonconstant rate curves before life
validation, Error::InvalidInput outside permitted valuation bounds or above
16,000 steps for a tree requiring rollback, and
Error::ComputationFailure for unstable probabilities, asset nodes or values.
§Greeks
Returns node delta/gamma and numerically completes missing requested Greeks.
Expiry Greeks follow terminal payoffs; time Greeks are absent. One-step gamma uses scalar differences.
Bumps use crate::NumericalShiftSettings; feasible bumped failures propagate.
§Errors
Checks flat-rate applicability before shift validation, then reuses
Self::price and crate::numerical_greeks errors.
§Examples
use kiyosi::PricingEngine;
use kiyosi::{AmericanOption, CoxRossRubinsteinVanillaEngine,
BlackScholesMertonParameters, Date, OptionType, PricingContext, Greek, GreeksRequest};
let start = Date::new(2025, 1, 1)?.start_of_day();
let option = AmericanOption::new(OptionType::Put, 100.0, start, Date::new(2026, 1, 1)?.start_of_day())?;
let context = PricingContext::new(
BlackScholesMertonParameters::new(0.05, 0.02, 0.2)?, 100.0, start.into())?;
let result = CoxRossRubinsteinVanillaEngine::default().price_with_greeks(
&option, &context, GreeksRequest::new([Greek::Delta]))?;
assert!(result.require(Greek::Delta)? < 0.0);Implementations§
Source§impl CoxRossRubinsteinVanillaEngine
impl CoxRossRubinsteinVanillaEngine
Sourcepub fn price_many(
&self,
options: &[BinomialVanilla<'_>],
context: &PricingContext,
) -> Result<Vec<f64>>
pub fn price_many( &self, options: &[BinomialVanilla<'_>], context: &PricingContext, ) -> Result<Vec<f64>>
Prices vanilla contracts in input order under one market snapshot.
Compatible American contracts can share lattice geometry and parallel
work runs on a bounded library pool. Configured American rollback
tolerances apply as in PricingEngine::price.
Each distinct contract is priced once, and duplicate prices retain their input positions.
§Examples
use kiyosi::{AmericanOption, BlackScholesMertonParameters, CoxRossRubinsteinVanillaEngine,
Date, OptionType, PricingContext, engines::BinomialVanilla};
let start = Date::new(2025, 1, 1)?.start_of_day();
let put = AmericanOption::new(OptionType::Put, 100.0, start, start.add_days(365)?)?;
let market = PricingContext::new(
BlackScholesMertonParameters::new(0.05, 0.02, 0.2)?, 100.0, start)?;
let prices = CoxRossRubinsteinVanillaEngine::default()
.price_many(&[BinomialVanilla::American(&put)], &market)?;
assert!(prices[0] > 0.0);§Errors
Returns crate::Error::InvalidInput above 1,048,576 contracts or for
excessive combined terminal-node, rollback or deterministic exercise work
across distinct contracts. The contract count includes duplicates.
Checks the deterministic batch work limit before exercise pricing.
Propagates the first contract pricing error in input order or a cancellation error.
A failed request returns no partial prices.
Source§impl CoxRossRubinsteinVanillaEngine
impl CoxRossRubinsteinVanillaEngine
Sourcepub fn new(settings: BinomialVanillaSettings) -> Result<Self>
pub fn new(settings: BinomialVanillaSettings) -> Result<Self>
Creates an engine with validated step count and rollback tolerance.
§Errors
Returns Error::InvalidInput outside 1 through 1,000,000 steps or for a
nonpositive or nonfinite tolerance. Pricing checks work limits for the
actual rollback path.
§Examples
use kiyosi::{CoxRossRubinsteinVanillaEngine, engines::BinomialVanillaSettings};
let settings = BinomialVanillaSettings {
step_count: 20_000,
rollback_tolerance: Some(1e-6),
};
let engine = CoxRossRubinsteinVanillaEngine::new(settings)?;
assert_eq!(engine.settings(), settings);Sourcepub fn settings(&self) -> BinomialVanillaSettings
pub fn settings(&self) -> BinomialVanillaSettings
Returns the complete engine settings. See Self::new for an example.
Trait Implementations§
impl Copy for CoxRossRubinsteinVanillaEngine
Source§impl PricingEngine for CoxRossRubinsteinVanillaEngine
impl PricingEngine for CoxRossRubinsteinVanillaEngine
Source§fn validate_applicability(&self, context: &PricingContext) -> Result<()>
fn validate_applicability(&self, context: &PricingContext) -> Result<()>
Source§fn greek_method(
&self,
option: &EuropeanOption,
context: &PricingContext,
) -> Result<GreekMethod>
fn greek_method( &self, option: &EuropeanOption, context: &PricingContext, ) -> Result<GreekMethod>
Source§fn price(
&self,
option: &EuropeanOption,
context: &PricingContext,
) -> Result<f64>
fn price( &self, option: &EuropeanOption, context: &PricingContext, ) -> Result<f64>
Source§fn price_with_greeks_with_settings(
&self,
option: &EuropeanOption,
context: &PricingContext,
request: GreeksRequest,
settings: NumericalShiftSettings,
) -> Result<PricingResult>
fn price_with_greeks_with_settings( &self, option: &EuropeanOption, context: &PricingContext, request: GreeksRequest, settings: NumericalShiftSettings, ) -> Result<PricingResult>
Source§fn prepare_implied_volatility(
&self,
option: &EuropeanOption,
context: &PricingContext,
settings: ImpliedVolatilitySettings,
) -> Result<ImpliedVolatilitySettings>
fn prepare_implied_volatility( &self, option: &EuropeanOption, context: &PricingContext, settings: ImpliedVolatilitySettings, ) -> Result<ImpliedVolatilitySettings>
Source§fn price_with_greeks(
&self,
option: &I,
context: &PricingContext,
request: GreeksRequest,
) -> Result<PricingResult>where
I: OptionContract,
fn price_with_greeks(
&self,
option: &I,
context: &PricingContext,
request: GreeksRequest,
) -> Result<PricingResult>where
I: OptionContract,
Source§fn default_spot_shift(&self, _option: &I, context: &PricingContext) -> f64
fn default_spot_shift(&self, _option: &I, context: &PricingContext) -> f64
Source§fn validate_solver_seed(&self) -> Result<()>
fn validate_solver_seed(&self) -> Result<()>
Source§fn prepare_request(&self) -> Result<Option<Box<dyn PricingEngine<I> + '_>>>
fn prepare_request(&self) -> Result<Option<Box<dyn PricingEngine<I> + '_>>>
Source§fn price_with_seed(
&self,
option: &I,
context: &PricingContext,
) -> Result<(f64, Option<u64>)>
fn price_with_seed( &self, option: &I, context: &PricingContext, ) -> Result<(f64, Option<u64>)>
None without sampling. Read moreSource§fn price_with_statistics(
&self,
_option: &I,
_context: &PricingContext,
) -> Result<MonteCarloEstimate>
fn price_with_statistics( &self, _option: &I, _context: &PricingContext, ) -> Result<MonteCarloEstimate>
Source§fn volatility_affects_price(&self, option: &I, context: &PricingContext) -> boolwhere
I: OptionContract,
fn volatility_affects_price(&self, option: &I, context: &PricingContext) -> boolwhere
I: OptionContract,
Source§impl PricingEngine<AmericanOption> for CoxRossRubinsteinVanillaEngine
impl PricingEngine<AmericanOption> for CoxRossRubinsteinVanillaEngine
Source§fn validate_applicability(&self, context: &PricingContext) -> Result<()>
fn validate_applicability(&self, context: &PricingContext) -> Result<()>
Source§fn greek_method(
&self,
option: &AmericanOption,
context: &PricingContext,
) -> Result<GreekMethod>
fn greek_method( &self, option: &AmericanOption, context: &PricingContext, ) -> Result<GreekMethod>
Source§fn price(
&self,
option: &AmericanOption,
context: &PricingContext,
) -> Result<f64>
fn price( &self, option: &AmericanOption, context: &PricingContext, ) -> Result<f64>
Source§fn price_with_greeks_with_settings(
&self,
option: &AmericanOption,
context: &PricingContext,
request: GreeksRequest,
settings: NumericalShiftSettings,
) -> Result<PricingResult>
fn price_with_greeks_with_settings( &self, option: &AmericanOption, context: &PricingContext, request: GreeksRequest, settings: NumericalShiftSettings, ) -> Result<PricingResult>
Source§fn prepare_implied_volatility(
&self,
option: &AmericanOption,
context: &PricingContext,
settings: ImpliedVolatilitySettings,
) -> Result<ImpliedVolatilitySettings>
fn prepare_implied_volatility( &self, option: &AmericanOption, context: &PricingContext, settings: ImpliedVolatilitySettings, ) -> Result<ImpliedVolatilitySettings>
Source§fn price_with_greeks(
&self,
option: &I,
context: &PricingContext,
request: GreeksRequest,
) -> Result<PricingResult>where
I: OptionContract,
fn price_with_greeks(
&self,
option: &I,
context: &PricingContext,
request: GreeksRequest,
) -> Result<PricingResult>where
I: OptionContract,
Source§fn default_spot_shift(&self, _option: &I, context: &PricingContext) -> f64
fn default_spot_shift(&self, _option: &I, context: &PricingContext) -> f64
Source§fn validate_solver_seed(&self) -> Result<()>
fn validate_solver_seed(&self) -> Result<()>
Source§fn prepare_request(&self) -> Result<Option<Box<dyn PricingEngine<I> + '_>>>
fn prepare_request(&self) -> Result<Option<Box<dyn PricingEngine<I> + '_>>>
Source§fn price_with_seed(
&self,
option: &I,
context: &PricingContext,
) -> Result<(f64, Option<u64>)>
fn price_with_seed( &self, option: &I, context: &PricingContext, ) -> Result<(f64, Option<u64>)>
None without sampling. Read moreSource§fn price_with_statistics(
&self,
_option: &I,
_context: &PricingContext,
) -> Result<MonteCarloEstimate>
fn price_with_statistics( &self, _option: &I, _context: &PricingContext, ) -> Result<MonteCarloEstimate>
Source§fn volatility_affects_price(&self, option: &I, context: &PricingContext) -> boolwhere
I: OptionContract,
fn volatility_affects_price(&self, option: &I, context: &PricingContext) -> boolwhere
I: OptionContract,
impl StructuralPartialEq for CoxRossRubinsteinVanillaEngine
Auto Trait Implementations§
impl Freeze for CoxRossRubinsteinVanillaEngine
impl RefUnwindSafe for CoxRossRubinsteinVanillaEngine
impl Send for CoxRossRubinsteinVanillaEngine
impl Sync for CoxRossRubinsteinVanillaEngine
impl Unpin for CoxRossRubinsteinVanillaEngine
impl UnsafeUnpin for CoxRossRubinsteinVanillaEngine
impl UnwindSafe for CoxRossRubinsteinVanillaEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more