Skip to main content

barrier_option

Function barrier_option 

Source
pub fn barrier_option(
    s: u128,
    k: u128,
    h: u128,
    r: u128,
    sigma: u128,
    t: u128,
    is_call: bool,
    barrier_type: BarrierType,
) -> Result<BarrierResult, SolMathError>
Expand description

Single barrier European option price via Rubinstein-Reiner building blocks.

Prices a European option with a single knock-in or knock-out barrier using Haug’s ABCD decomposition, verified against QuantLib on 443K vectors.

This formula assumes continuous monitoring, zero rebate, no dividends, and that the barrier has not been breached before the valuation instant. On-chain callers with persisted path state should use barrier_option_with_state. Discretely sampled oracle barriers require a separate monitoring correction and must not be priced as continuous.

§Parameters

  • s – Spot price at SCALE (u128)
  • k – Strike price at SCALE (u128)
  • h – Barrier level at SCALE (u128)
  • r – Risk-free rate at SCALE (u128, e.g. 50_000_000_000 = 5%)
  • sigma – Volatility at SCALE (u128, e.g. 250_000_000_000 = 25%)
  • t – Time to expiry in years at SCALE (u128)
  • is_calltrue for call, false for put
  • barrier_typeBarrierType variant

§Errors

Returns Err(DomainError) if s, k, h, sigma, or t are zero.

§Accuracy

Max 1.7K ULP, P99 33, median 1. Final SBF audit: 270,156 CU average and 415,531 max for this math call.

Public return values preserve exact in/out conservation after rounding.

§Example

use solmath::{barrier_option, BarrierType, SCALE};
let result = barrier_option(
    100 * SCALE, 100 * SCALE, 90 * SCALE,
    50_000_000_000, 250_000_000_000, SCALE,
    true, BarrierType::DownAndOut,
)?;
assert!(result.price > 0);
assert!(result.price <= result.vanilla);