Skip to main content

CoxRossRubinsteinVanillaEngine

Struct CoxRossRubinsteinVanillaEngine 

Source
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

Source

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

Source

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);
Source

pub fn settings(&self) -> BinomialVanillaSettings

Returns the complete engine settings. See Self::new for an example.

Trait Implementations§

Source§

impl Clone for CoxRossRubinsteinVanillaEngine

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for CoxRossRubinsteinVanillaEngine

Source§

impl Debug for CoxRossRubinsteinVanillaEngine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CoxRossRubinsteinVanillaEngine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for CoxRossRubinsteinVanillaEngine

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PricingEngine for CoxRossRubinsteinVanillaEngine

Source§

fn validate_applicability(&self, context: &PricingContext) -> Result<()>

Checks engine applicability before numerical requests or implied-volatility validation. Read more
Source§

fn greek_method( &self, option: &EuropeanOption, context: &PricingContext, ) -> Result<GreekMethod>

Reports the native Greek calculation path without pricing or drawing samples. Read more
Source§

fn price( &self, option: &EuropeanOption, context: &PricingContext, ) -> Result<f64>

Prices a supported contract. Read more
Source§

fn price_with_greeks_with_settings( &self, option: &EuropeanOption, context: &PricingContext, request: GreeksRequest, settings: NumericalShiftSettings, ) -> Result<PricingResult>

Returns native sensitivities with explicit request-level numerical controls. Read more
Source§

fn prepare_implied_volatility( &self, option: &EuropeanOption, context: &PricingContext, settings: ImpliedVolatilitySettings, ) -> Result<ImpliedVolatilitySettings>

Restricts a validated solver bracket to the engine’s supported domain. Read more
Source§

fn price_with_greeks( &self, option: &I, context: &PricingContext, request: GreeksRequest, ) -> Result<PricingResult>
where I: OptionContract,

Returns requested sensitivities using shared bump defaults. Read more
Source§

fn default_spot_shift(&self, _option: &I, context: &PricingContext) -> f64

Returns the automatic pre-expiry spot bump for this engine and contract family. Read more
Source§

fn validate_solver_seed(&self) -> Result<()>

Checks that a solver’s random draws can be replayed by the caller. Read more
Source§

fn prepare_request(&self) -> Result<Option<Box<dyn PricingEngine<I> + '_>>>

Prepares request-local state for numerical Greeks and implied-parameter solvers. Read more
Source§

fn price_with_seed( &self, option: &I, context: &PricingContext, ) -> Result<(f64, Option<u64>)>

Returns a scalar price and the seed used, or None without sampling. Read more
Source§

fn price_with_statistics( &self, _option: &I, _context: &PricingContext, ) -> Result<MonteCarloEstimate>

Returns a price with sampling uncertainty when the engine provides an estimator. Read more
Source§

fn volatility_affects_price(&self, option: &I, context: &PricingContext) -> bool
where I: OptionContract,

Reports whether volatility affects a validated contract’s remaining payoff. Read more
Source§

impl PricingEngine<AmericanOption> for CoxRossRubinsteinVanillaEngine

Source§

fn validate_applicability(&self, context: &PricingContext) -> Result<()>

Checks engine applicability before numerical requests or implied-volatility validation. Read more
Source§

fn greek_method( &self, option: &AmericanOption, context: &PricingContext, ) -> Result<GreekMethod>

Reports the native Greek calculation path without pricing or drawing samples. Read more
Source§

fn price( &self, option: &AmericanOption, context: &PricingContext, ) -> Result<f64>

Prices a supported contract. Read more
Source§

fn price_with_greeks_with_settings( &self, option: &AmericanOption, context: &PricingContext, request: GreeksRequest, settings: NumericalShiftSettings, ) -> Result<PricingResult>

Returns native sensitivities with explicit request-level numerical controls. Read more
Source§

fn prepare_implied_volatility( &self, option: &AmericanOption, context: &PricingContext, settings: ImpliedVolatilitySettings, ) -> Result<ImpliedVolatilitySettings>

Restricts a validated solver bracket to the engine’s supported domain. Read more
Source§

fn price_with_greeks( &self, option: &I, context: &PricingContext, request: GreeksRequest, ) -> Result<PricingResult>
where I: OptionContract,

Returns requested sensitivities using shared bump defaults. Read more
Source§

fn default_spot_shift(&self, _option: &I, context: &PricingContext) -> f64

Returns the automatic pre-expiry spot bump for this engine and contract family. Read more
Source§

fn validate_solver_seed(&self) -> Result<()>

Checks that a solver’s random draws can be replayed by the caller. Read more
Source§

fn prepare_request(&self) -> Result<Option<Box<dyn PricingEngine<I> + '_>>>

Prepares request-local state for numerical Greeks and implied-parameter solvers. Read more
Source§

fn price_with_seed( &self, option: &I, context: &PricingContext, ) -> Result<(f64, Option<u64>)>

Returns a scalar price and the seed used, or None without sampling. Read more
Source§

fn price_with_statistics( &self, _option: &I, _context: &PricingContext, ) -> Result<MonteCarloEstimate>

Returns a price with sampling uncertainty when the engine provides an estimator. Read more
Source§

fn volatility_affects_price(&self, option: &I, context: &PricingContext) -> bool
where I: OptionContract,

Reports whether volatility affects a validated contract’s remaining payoff. Read more
Source§

impl StructuralPartialEq for CoxRossRubinsteinVanillaEngine

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.