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
impl FiniteDifferenceBarrierEngine
Sourcepub fn new(settings: FiniteDifferenceSettings) -> Result<Self>
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);Sourcepub fn settings(&self) -> FiniteDifferenceSettings
pub fn settings(&self) -> FiniteDifferenceSettings
Returns copied settings. See Self::new for an example.
Trait Implementations§
impl Copy for FiniteDifferenceBarrierEngine
Source§impl FiniteDifferenceEngine<BarrierOption> for FiniteDifferenceBarrierEngine
impl FiniteDifferenceEngine<BarrierOption> for FiniteDifferenceBarrierEngine
Source§fn solve(
&self,
option: &BarrierOption,
context: &PricingContext,
range: RangeInclusive<f64>,
) -> Result<FiniteDifferenceSolution>
fn solve( &self, option: &BarrierOption, context: &PricingContext, range: RangeInclusive<f64>, ) -> Result<FiniteDifferenceSolution>
Source§impl PricingEngine<BarrierOption> for FiniteDifferenceBarrierEngine
impl PricingEngine<BarrierOption> for FiniteDifferenceBarrierEngine
Source§fn price(&self, option: &BarrierOption, context: &PricingContext) -> Result<f64>
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>
fn greek_method( &self, option: &BarrierOption, context: &PricingContext, ) -> Result<GreekMethod>
Source§fn validate_applicability(&self, context: &PricingContext) -> Result<()>
fn validate_applicability(&self, context: &PricingContext) -> Result<()>
Source§fn volatility_affects_price(
&self,
option: &BarrierOption,
context: &PricingContext,
) -> bool
fn volatility_affects_price( &self, option: &BarrierOption, context: &PricingContext, ) -> bool
Source§fn price_with_greeks_with_settings(
&self,
option: &BarrierOption,
context: &PricingContext,
request: GreeksRequest,
shifts: NumericalShiftSettings,
) -> Result<PricingResult>
fn price_with_greeks_with_settings( &self, option: &BarrierOption, context: &PricingContext, request: GreeksRequest, shifts: NumericalShiftSettings, ) -> Result<PricingResult>
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 prepare_implied_volatility(
&self,
_option: &I,
_context: &PricingContext,
settings: ImpliedVolatilitySettings,
) -> Result<ImpliedVolatilitySettings>
fn prepare_implied_volatility( &self, _option: &I, _context: &PricingContext, settings: ImpliedVolatilitySettings, ) -> Result<ImpliedVolatilitySettings>
impl StructuralPartialEq for FiniteDifferenceBarrierEngine
Auto Trait Implementations§
impl Freeze for FiniteDifferenceBarrierEngine
impl RefUnwindSafe for FiniteDifferenceBarrierEngine
impl Send for FiniteDifferenceBarrierEngine
impl Sync for FiniteDifferenceBarrierEngine
impl Unpin for FiniteDifferenceBarrierEngine
impl UnsafeUnpin for FiniteDifferenceBarrierEngine
impl UnwindSafe for FiniteDifferenceBarrierEngine
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