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 BarrierOption

From Leeroopedia


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

Overview

Implements the BarrierOption struct and its Payoff trait for computing the payoff of barrier options that activate or deactivate when the underlying crosses a specified barrier level.

Description

The BarrierOption struct represents an exotic option whose payoff depends on whether the underlying asset's price path crosses a predefined barrier level during the option's life. The struct holds an OptionContract, a BarrierType (specifying the barrier behavior), the barrier level, a strike price, and an optional rebate amount.

The Payoff implementation accepts a Vec<f64> representing the price path. It checks whether any value in the path crosses the barrier (above or below) and then determines the payoff based on the four barrier types:

  • UpAndOut: Pays the vanilla payoff if the barrier was never breached from above; otherwise pays 0
  • DownAndOut: Pays the vanilla payoff if the barrier was never breached from below; otherwise pays 0
  • UpAndIn: Pays the vanilla payoff only if the barrier was breached from above; otherwise pays 0
  • DownAndIn: Pays the vanilla payoff only if the barrier was breached from below; otherwise pays 0

The vanilla payoff is max(S_T - K, 0) for calls and max(K - S_T, 0) for puts, where S_T is the terminal price.

Usage

Use this struct when computing the payoff of barrier options in path-dependent pricing frameworks such as Monte Carlo simulation.

Code Reference

Source Location

Signature

#[derive(Debug, Clone)]
pub struct BarrierOption {
    pub contract: OptionContract,
    pub barrier_type: BarrierType,
    pub barrier: f64,
    pub strike: f64,
    pub rebate: Option<f64>,
}

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

Import

use RustQuant::instruments::options::barrier::BarrierOption;

I/O Contract

Inputs

Name Type Required Description
contract OptionContract Yes The base option contract (type_flag, exercise_flag)
barrier_type BarrierType Yes One of UpAndOut, DownAndOut, UpAndIn, DownAndIn
barrier f64 Yes The barrier level that triggers activation or deactivation
strike f64 Yes The strike price of the option
rebate Option<f64> No Optional rebate paid when the option is knocked out (not yet used in payoff)
underlying (payoff) Vec<f64> Yes Price path of the underlying asset

Outputs

Name Type Description
payoff() f64 The barrier option payoff: vanilla payoff if barrier condition is met, 0 otherwise

Usage Examples

use RustQuant::instruments::options::barrier::BarrierOption;
use RustQuant::instruments::options::{OptionContract, TypeFlag, ExerciseFlag, BarrierType};
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 barrier_opt = BarrierOption {
    contract,
    barrier_type: BarrierType::UpAndOut,
    barrier: 120.0,
    strike: 100.0,
    rebate: None,
};

let path = vec![100.0, 105.0, 110.0, 108.0, 112.0];
let payoff = barrier_opt.payoff(path);
// Call payoff: max(112 - 100, 0) = 12 since barrier 120 was not breached

Related Pages

Page Connections

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