Implementation:Avhz RustQuant BinaryOption
| 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
- Repository: RustQuant
- File: crates/RustQuant_instruments/src/options/binary.rs
- Lines: 1-54
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