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
utoipasupport via feature flag - Helpers:
is_european(),is_exotic(),is_path_dependent(),is_multi_asset(), and more
Dependencies
financial_types—OptionStyle,Sidepositive— Type-safe positive decimal valuesexpiration_date— Expiration date handling
Installation
Add this to your Cargo.toml:
[]
= "0.1"
To enable OpenAPI schema support:
[]
= { = "0.1", = ["utoipa"] }
Quick Start
use ;
// Standard options
let european = European;
assert!;
assert!;
// Exotic options
let asian = Asian ;
assert!;
assert!;
// Barrier options
let barrier = Barrier ;
assert!;
// Display
assert_eq!;
API
OptionType
The main enum classifying option contracts:
use OptionType;
let opt = default; // European
assert!;
assert!;
assert!;
assert!;
Helpers: is_european(), is_american(), is_exotic(), is_path_dependent(), is_multi_asset()
BarrierType
use BarrierType;
let barrier = UpAndIn;
assert!;
assert!;
assert!;
assert!;
Helpers: is_knock_in(), is_knock_out(), is_up(), is_down()
AsianAveragingType
use AsianAveragingType;
let avg = Arithmetic;
assert!;
assert!;
Helpers: is_arithmetic(), is_geometric()
RainbowType
use RainbowType;
let rainbow = BestOf;
assert!;
assert!;
Helpers: is_best_of(), is_worst_of()
OptionBasicType
A lightweight struct referencing core option properties:
use OptionBasicType;
use ;
use Positive;
use ExpirationDate;
use pos_or_panic;
let style = Call;
let side = Long;
let strike = new.unwrap;
let expiry = Days;
let basic = OptionBasicType ;
Serialization
use ;
let opt = Asian ;
let json = to_string.unwrap;
let parsed: OptionType = from_str.unwrap;
assert_eq!;
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:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and ensure that the project still builds and all tests pass.
- Commit your changes and push your branch to your forked repository.
- 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
- Author: Joaquín Béjar García
- Email: jb@taunais.com
- Telegram: @joaquin_bejar
- Repository: https://github.com/joaquinbejar/option_type
- Documentation: https://docs.rs/option_type
We appreciate your interest and look forward to your contributions!
✍️ License
Licensed under MIT license