Implementation:Avhz RustQuant OptionContract
| Knowledge Sources | |
|---|---|
| Domains | Options, Quantitative_Finance |
| Last Updated | 2026-02-07 19:00 GMT |
Overview
Defines the OptionContract struct that serves as the core data container for all option types in the library, specifying the fundamental contract parameters shared by every option.
Description
The OptionContract struct is the foundational building block used by all option structs in the library (Asian, Barrier, Binary, Lookback, Power, Supershare, Log, etc.). It encapsulates four key parameters:
- type_flag (TypeFlag): Mandatory. Specifies whether the option is a Call or Put.
- exercise_flag (ExerciseFlag): Mandatory. Specifies the exercise style -- European (single expiry), American (range of dates), or Bermudan (specific exercise dates).
- strike_flag (Option<StrikeFlag>): Optional. Indicates whether the strike is fixed or floating, used by Asian and Lookback options.
- settlement_flag (Option<SettlementFlag>): Optional. Indicates cash or physical settlement.
The struct derives Debug and Clone and uses the derive_builder crate to provide an OptionContractBuilder with defaults for the optional fields.
Usage
Use this struct as a building block when constructing any option type. It is embedded as a field in every exotic and vanilla option struct in the library.
Code Reference
Source Location
- Repository: RustQuant
- File: crates/RustQuant_instruments/src/options/option_contract.rs
- Lines: 1-29
Signature
#[derive(Debug, Clone, Builder)]
pub struct OptionContract {
pub type_flag: TypeFlag,
pub exercise_flag: ExerciseFlag,
#[builder(default)]
pub strike_flag: Option<StrikeFlag>,
#[builder(default)]
pub settlement_flag: Option<SettlementFlag>,
}
Import
use RustQuant::instruments::options::option_contract::OptionContract;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| type_flag | TypeFlag | Yes | Call or Put |
| exercise_flag | ExerciseFlag | Yes | European, American, or Bermudan exercise style |
| strike_flag | Option<StrikeFlag> | No | Fixed or Floating strike (defaults to None) |
| settlement_flag | Option<SettlementFlag> | No | Cash or Physical settlement (defaults to None) |
Outputs
| Name | Type | Description |
|---|---|---|
| (struct fields) | -- | Data container; accessed directly by all option structs that embed it |
Usage Examples
use RustQuant::instruments::options::option_contract::OptionContract;
use RustQuant::instruments::options::option_flags::*;
// Using direct construction
let contract = OptionContract {
type_flag: TypeFlag::Call,
exercise_flag: ExerciseFlag::European { expiry: expiry_date },
strike_flag: Some(StrikeFlag::Fixed),
settlement_flag: None,
};
// Using the builder pattern
let contract = OptionContractBuilder::default()
.type_flag(TypeFlag::Put)
.exercise_flag(ExerciseFlag::American { start: start_date, end: end_date })
.build()
.unwrap();