Skip to main content

FiniteDifferenceBarrierEngine

Struct FiniteDifferenceBarrierEngine 

Source
pub struct FiniteDifferenceBarrierEngine { /* private fields */ }
Expand description

Prices single-barrier contracts with exact continuous edges and scheduled event projection.

Distinct and shared instances support concurrent pricing.

See Self::price for usage.

Implementations§

Source§

impl FiniteDifferenceBarrierEngine

Source

pub fn new(settings: FiniteDifferenceSettings) -> Result<Self>

Creates an engine after validating grid sizes and any explicit upper boundary.

§Errors

Returns Error::InvalidInput for fewer than three asset steps, nonpositive time steps, a grid exceeding the workspace or rollback work limit, or a nonpositive or non-finite upper boundary. Validation precedes storing settings; no grid is allocated here. See Self::price for engine-specific usage.

§Examples
use kiyosi::{FiniteDifferenceVanillaEngine, engines::{FiniteDifferenceScheme,
    FiniteDifferenceSettings}};
let engine = FiniteDifferenceVanillaEngine::new(FiniteDifferenceSettings {
    asset_step_count: 400, scheme: FiniteDifferenceScheme::ImplicitEuler,
    ..Default::default()
})?;
assert_eq!(engine.settings().asset_step_count, 400);
Source

pub fn settings(&self) -> FiniteDifferenceSettings

Returns copied settings. See Self::new for an example.

Trait Implementations§

Source§

impl Clone for FiniteDifferenceBarrierEngine

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 FiniteDifferenceBarrierEngine

Source§

impl Debug for FiniteDifferenceBarrierEngine

Source§

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

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

impl Default for FiniteDifferenceBarrierEngine

Source§

fn default() -> Self

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

impl FiniteDifferenceEngine<BarrierOption> for FiniteDifferenceBarrierEngine

Source§

fn solve( &self, option: &BarrierOption, context: &PricingContext, range: RangeInclusive<f64>, ) -> Result<FiniteDifferenceSolution>

Solves for a finite, positive, strictly increasing closed spot interval. Read more
Source§

impl PartialEq for FiniteDifferenceBarrierEngine

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<BarrierOption> for FiniteDifferenceBarrierEngine

Source§

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

Prices a single barrier with continuous or scheduled monitoring and flat or nonconstant rate curves.

Resolves current observations against actual spot before building a grid. Prior at-hit rebates are already paid; resolved vanilla payoffs use the selected model. Local volatility supports price, delta and gamma, holding the surface fixed. Continuous barriers define exact domain edges, and time grids include exact scheduled dates. The configured upper bound is used only when pricing needs a full upper domain. Continuous single-barrier payoffs and local-volatility knock-in continuations use cell averaging at the strike. See Self::price for an example.

§Errors

Missing required history returns crate::Error::MissingHistory; see the caller-supplied history contract.

Returns Error::InvalidInput outside life or required curve/surface coverage, for impossible history, clipped or degenerate grids, or unstable explicit steps. Numerical failures return Error::ComputationFailure. Scheduled constant-volatility grids also fail when one-sided drift on the mesh would introduce excessive variance. Increase spatial resolution in that case.

§Greeks

Returns spline delta/gamma and fixed-grid speed, completing other Greeks numerically.

Scheduled flat-rate BSM grids reuse the pricing factorization for eligible default first-order market sensitivities. Custom bumps reprice the contract using NumericalShiftSettings and the central BSM upper boundary. Local volatility accepts only delta/gamma, holding the absolute surface fixed. Stencils crossing observations or barriers that change cash flows can leave Greeks absent. Expiry Greeks follow terminal payoffs. Before expiry at positive BSM volatility, spot derivatives can be undefined where a touch changes cash flows. Rate and volatility Greeks follow the resolved payoff.

§Errors

Validates shifts before pricing. Propagates Self::price and crate::numerical_greeks errors; feasible bumped failures fail the operation.

§Examples
use kiyosi::*;
let start = Date::new(2025, 1, 1)?.start_of_day();
let option = BarrierOption::new(BarrierOptionTerms::new(OptionType::Call, 100.0,
    start, Date::new(2026, 1, 1)?.start_of_day(), 120.0, BarrierType::UpAndOut))?;
let context = PricingContext::new(BlackScholesMertonParameters::new(0.04, 0.01, 0.2)?,
    100.0, start.into())?;
let engine = FiniteDifferenceBarrierEngine::default();
assert_eq!(engine.settings().asset_step_count, 800);
let result = engine.price_with_greeks_with_settings(&option, &context,
    GreeksRequest::new([Greek::Delta]),
    NumericalShiftSettings { spot_shift: Some(0.001), ..Default::default() })?;
assert_eq!(result.price(), engine.price(&option, &context)?);
assert!(result.get(Greek::Delta).is_some());
Source§

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

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

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

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

fn volatility_affects_price( &self, option: &BarrierOption, context: &PricingContext, ) -> bool

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

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

Returns native sensitivities with explicit request-level numerical controls. 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 prepare_implied_volatility( &self, _option: &I, _context: &PricingContext, settings: ImpliedVolatilitySettings, ) -> Result<ImpliedVolatilitySettings>

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

impl StructuralPartialEq for FiniteDifferenceBarrierEngine

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.