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 Binary Backend

From Leeroopedia


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

Overview

Concrete tool for pricing binary (digital) option types including gap options and cash-or-nothing options provided by the RustQuant library.

Description

This module implements closed-form pricing for two binary/digital option types:

  • GapOption -- A gap option has two strike prices: a barrier strike K_1 that determines whether the option pays out, and a payoff strike K_2 that determines the payoff amount. The call payoff is 0 if S < K_1 and S - K_2 if S > K_1. Note that gap option payoffs can be negative. The pricing uses a standard BSM-like formula with the Gaussian CDF, incorporating a cost-of-carry parameter.
  • CashOrNothingOption -- Pays a fixed cash amount K if the option finishes in the money, and zero otherwise. The call pays K if S > X at expiry, and the put pays K if S < X.

Both structs compute d1/d2 using log-price ratios and return (call_price, put_price) tuples.

Usage

Use when pricing digital/binary option payoffs, gap options with dual-strike structures, or cash-or-nothing instruments analytically.

Code Reference

Source Location

Signature

#[derive(Debug, Clone, Copy)]
pub struct GapOption {
    pub initial_price: f64,
    pub strike_1: f64,
    pub strike_2: f64,
    pub risk_free_rate: f64,
    pub volatility: f64,
    pub cost_of_carry: f64,
    pub time_to_maturity: f64,
}

impl GapOption {
    #[must_use]
    pub fn price(&self) -> (f64, f64)
}

#[derive(Debug, Clone, Copy)]
pub struct CashOrNothingOption {
    pub initial_price: f64,
    pub strike_price: f64,
    pub payout_value: f64,
    pub risk_free_rate: f64,
    pub volatility: f64,
    pub cost_of_carry: f64,
    pub time_to_maturity: f64,
}

impl CashOrNothingOption {
    #[must_use]
    pub fn price(&self) -> (f64, f64)
}

Import

use RustQuant::instruments::{GapOption, CashOrNothingOption};

I/O Contract

Inputs (GapOption)

Name Type Required Description
initial_price f64 Yes Initial underlying price (S)
strike_1 f64 Yes Barrier strike price (K_1) determining exercise
strike_2 f64 Yes Payoff strike price (K_2) determining payoff amount
risk_free_rate f64 Yes Risk-free interest rate (r)
volatility f64 Yes Volatility parameter (v)
cost_of_carry f64 Yes Cost of carry (b)
time_to_maturity f64 Yes Time to expiry in years (T)

Inputs (CashOrNothingOption)

Name Type Required Description
initial_price f64 Yes Initial underlying price (S)
strike_price f64 Yes Strike price (X)
payout_value f64 Yes Fixed cash payout amount (K)
risk_free_rate f64 Yes Risk-free interest rate (r)
volatility f64 Yes Volatility parameter (v)
cost_of_carry f64 Yes Cost of carry (b)
time_to_maturity f64 Yes Time to expiry in years (T)

Outputs

Name Type Description
(call, put) (f64, f64) Tuple of call and put option prices

Usage Examples

use RustQuant::instruments::{GapOption, CashOrNothingOption};

// Gap option example (from Haug's book)
let gap = GapOption {
    initial_price: 50.0,
    strike_1: 50.0,
    strike_2: 57.0,
    risk_free_rate: 0.09,
    volatility: 0.2,
    time_to_maturity: 0.5,
    cost_of_carry: 0.09,
};
let (gap_call, gap_put) = gap.price();

// Cash-or-Nothing option example
let con = CashOrNothingOption {
    initial_price: 100.0,
    payout_value: 10.0,
    strike_price: 80.0,
    risk_free_rate: 0.06,
    volatility: 0.35,
    time_to_maturity: 0.75,
    cost_of_carry: 0.0,
};
let (con_call, con_put) = con.price();

Related Pages

Page Connections

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