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 BinaryOption

From Leeroopedia


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

Overview

Implements the BinaryOption struct and its Payoff trait for computing the payoff of binary (digital) options that pay a fixed amount or the asset value upon expiry based on a condition.

Description

The BinaryOption struct represents an exotic option with a discontinuous payoff. It wraps an OptionContract, a strike price, and a BinaryType flag that determines the payout structure.

The Payoff implementation accepts a single f64 (the terminal underlying price) and computes the payoff based on two binary types:

  • CashOrNothing: Pays the strike amount if the option finishes in-the-money, otherwise pays 0. For a call, this means the underlying must exceed the strike; for a put, the underlying must be below the strike.
  • AssetOrNothing: Pays the underlying asset value if the option finishes in-the-money, otherwise pays 0.

Usage

Use this struct when pricing binary or digital options. Binary options are commonly found in structured products and exotic derivatives.

Code Reference

Source Location

Signature

#[derive(Debug, Clone)]
pub struct BinaryOption {
    pub contract: OptionContract,
    pub strike: f64,
    pub binary_type: BinaryType,
}

impl Payoff for BinaryOption {
    type Underlying = f64;
    fn payoff(&self, underlying: Self::Underlying) -> f64;
}

Import

use RustQuant::instruments::options::binary::BinaryOption;

I/O Contract

Inputs

Name Type Required Description
contract OptionContract Yes The base option contract (type_flag for Call/Put)
strike f64 Yes The strike price that determines the in-the-money condition
binary_type BinaryType Yes CashOrNothing or AssetOrNothing
underlying (payoff) f64 Yes Terminal price of the underlying asset

Outputs

Name Type Description
payoff() f64 For CashOrNothing: strike if ITM, 0 otherwise. For AssetOrNothing: underlying if ITM, 0 otherwise

Usage Examples

use RustQuant::instruments::options::binary::BinaryOption;
use RustQuant::instruments::options::{OptionContract, TypeFlag, ExerciseFlag, BinaryType};
use RustQuant::instruments::Payoff;

let contract = OptionContract {
    type_flag: TypeFlag::Call,
    exercise_flag: ExerciseFlag::European { expiry: expiry_date },
    strike_flag: None,
    settlement_flag: None,
};

let binary = BinaryOption {
    contract,
    strike: 100.0,
    binary_type: BinaryType::CashOrNothing,
};

let payoff = binary.payoff(105.0);
// CashOrNothing call with S=105 > K=100: pays 100.0 (the strike)

let payoff_otm = binary.payoff(95.0);
// S=95 < K=100: pays 0.0

Related Pages

Page Connections

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