Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Avhz RustQuant Barrier Backend

From Leeroopedia


Knowledge Sources
Domains Option_Pricing, Quantitative_Finance
Last Updated 2026-02-07 19:00 GMT

Overview

Concrete tool for pricing path-dependent barrier options analytically provided by the RustQuant library.

Description

This module implements closed-form pricing for barrier options using the generalized analytical formulas from Haug's Complete Guide to Option Pricing Formulas. It defines a BarrierOption struct and a BarrierType enum covering all eight standard barrier option types: call/put combined with up/down and in/out (CUI, CDI, CUO, CDO, PUI, PDI, PUO, PDO). The pricing method computes intermediate terms (A, B, C, D, E, F) involving the Gaussian CDF and combines them according to the barrier type and the relationship between the strike and barrier levels. The cost of carry is derived as b = r - q.

Usage

Use when pricing European-style barrier options analytically. The caller must ensure the initial underlying price does not already breach the barrier in an invalid direction; otherwise the method panics.

Code Reference

Source Location

Signature

#[derive(Debug, Clone, Copy)]
pub struct BarrierOption {
    pub initial_price: f64,
    pub strike_price: f64,
    pub barrier: f64,
    pub time_to_expiry: f64,
    pub risk_free_rate: f64,
    pub volatility: f64,
    pub rebate: f64,
    pub dividend_yield: f64,
}

#[derive(Debug, Clone, Copy)]
pub enum BarrierType {
    CUI, CDI, CUO, CDO,
    PUI, PDI, PUO, PDO,
}

impl BarrierOption {
    #[must_use]
    pub fn price(&self, type_flag: BarrierType) -> f64
}

Import

use RustQuant::instruments::{BarrierOption, BarrierType};

I/O Contract

Inputs

Name Type Required Description
initial_price f64 Yes Initial underlying asset price (S)
strike_price f64 Yes Strike price (X)
barrier f64 Yes Barrier level (H)
time_to_expiry f64 Yes Time to expiration in years (T)
risk_free_rate f64 Yes Risk-free interest rate (r)
volatility f64 Yes Volatility of the underlying (v)
rebate f64 Yes Rebate paid if option cannot be exercised (K)
dividend_yield f64 Yes Continuous dividend yield (q)
type_flag BarrierType Yes One of CUI, CDI, CUO, CDO, PUI, PDI, PUO, PDO

Outputs

Name Type Description
price f64 The analytical barrier option price

Usage Examples

use RustQuant::instruments::{BarrierOption, BarrierType};

let option = BarrierOption {
    initial_price: 110.0,
    strike_price: 100.0,
    barrier: 105.0,
    time_to_expiry: 1.0,
    risk_free_rate: 0.05,
    volatility: 0.2,
    rebate: 0.0,
    dividend_yield: 0.01,
};

// Price a down-and-in call (S > H required for down barriers)
let cdi_price = option.price(BarrierType::CDI);
// Price a down-and-out call
let cdo_price = option.price(BarrierType::CDO);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment