option_type 0.1.0

Option contract type definitions including exotic options: Asian, Barrier, Binary, Lookback, Rainbow, and more.
Documentation

Dual License Crates.io Downloads Stars Issues PRs Build Status Coverage Dependencies Documentation Wiki

Option Type

Option contract type definitions including standard and exotic options for Rust.

Overview

option_type is a Rust crate providing a comprehensive enum-based classification of financial option contracts. It covers both standard vanilla options (European, American) and a wide range of exotic option types.

All leaf sub-enums use #[repr(u8)] for compact memory layout (1 byte each). Pure helper methods are annotated with #[must_use] and #[inline].

Supported Option Types

Category Types
Standard European, American
Path-dependent Asian, Barrier, Lookback, Cliquet
Multi-asset Rainbow, Spread, Exchange
Structural Compound, Chooser, Binary, Bermuda
Modified payoff Power, Quanto

Sub-type Enums

Enum Variants Description
AsianAveragingType Arithmetic, Geometric Averaging method for Asian options
BarrierType UpAndIn, UpAndOut, DownAndIn, DownAndOut Barrier trigger conditions
BinaryType CashOrNothing, AssetOrNothing, Gap Binary option payout types
LookbackType FixedStrike, FloatingStrike Lookback strike determination
RainbowType BestOf, WorstOf Multi-asset selection method

Features

  • Comprehensive: 15 option type variants covering vanilla and exotic options
  • Compact sub-enums: All leaf enums are #[repr(u8)] — 1 byte each
  • Safe: #[must_use] on all pure helper methods
  • Serde: Full serialization/deserialization support
  • OpenAPI: Optional utoipa support via feature flag
  • Helpers: is_european(), is_exotic(), is_path_dependent(), is_multi_asset(), and more

Dependencies

Installation

Add this to your Cargo.toml:

[dependencies]
option_type = "0.1"

To enable OpenAPI schema support:

[dependencies]
option_type = { version = "0.1", features = ["utoipa"] }

Quick Start

use option_type::{OptionType, AsianAveragingType, BarrierType};

// Standard options
let european = OptionType::European;
assert!(european.is_european());
assert!(!european.is_exotic());

// Exotic options
let asian = OptionType::Asian {
    averaging_type: AsianAveragingType::Arithmetic,
};
assert!(asian.is_exotic());
assert!(asian.is_path_dependent());

// Barrier options
let barrier = OptionType::Barrier {
    barrier_type: BarrierType::UpAndIn,
    barrier_level: 120.0,
    rebate: None,
};
assert!(barrier.is_path_dependent());

// Display
assert_eq!(format!("{european}"), "European Option");

API

OptionType

The main enum classifying option contracts:

use option_type::OptionType;

let opt = OptionType::default(); // European
assert!(opt.is_european());
assert!(!opt.is_exotic());
assert!(!opt.is_path_dependent());
assert!(!opt.is_multi_asset());

Helpers: is_european(), is_american(), is_exotic(), is_path_dependent(), is_multi_asset()

BarrierType

use option_type::BarrierType;

let barrier = BarrierType::UpAndIn;
assert!(barrier.is_knock_in());
assert!(barrier.is_up());
assert!(!barrier.is_knock_out());
assert!(!barrier.is_down());

Helpers: is_knock_in(), is_knock_out(), is_up(), is_down()

AsianAveragingType

use option_type::AsianAveragingType;

let avg = AsianAveragingType::Arithmetic;
assert!(avg.is_arithmetic());
assert!(!avg.is_geometric());

Helpers: is_arithmetic(), is_geometric()

RainbowType

use option_type::RainbowType;

let rainbow = RainbowType::BestOf;
assert!(rainbow.is_best_of());
assert!(!rainbow.is_worst_of());

Helpers: is_best_of(), is_worst_of()

OptionBasicType

A lightweight struct referencing core option properties:

use option_type::OptionBasicType;
use financial_types::{OptionStyle, Side};
use positive::Positive;
use expiration_date::ExpirationDate;
use positive::pos_or_panic;

let style = OptionStyle::Call;
let side = Side::Long;
let strike = Positive::new(100.0).unwrap();
let expiry = ExpirationDate::Days(pos_or_panic!(30.0));

let basic = OptionBasicType {
    option_style: &style,
    side: &side,
    strike_price: &strike,
    expiration_date: &expiry,
};

Serialization

use option_type::{OptionType, AsianAveragingType};

let opt = OptionType::Asian {
    averaging_type: AsianAveragingType::Geometric,
};
let json = serde_json::to_string(&opt).unwrap();
let parsed: OptionType = serde_json::from_str(&json).unwrap();
assert_eq!(opt, parsed);

License

This project is licensed under the MIT License.

Contribution and Contact

We welcome contributions to this project! If you would like to contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and ensure that the project still builds and all tests pass.
  4. Commit your changes and push your branch to your forked repository.
  5. Submit a pull request to the main repository.

If you have any questions, issues, or would like to provide feedback, please feel free to contact the project maintainer:

Contact Information

We appreciate your interest and look forward to your contributions!

✍️ License

Licensed under MIT license