#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum OptionType {
Call,
Put,
}
impl OptionType {
#[inline]
#[must_use]
pub const fn is_call(self) -> bool {
matches!(self, OptionType::Call)
}
}
impl std::fmt::Display for OptionType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
OptionType::Call => write!(f, "Call"),
OptionType::Put => write!(f, "Put"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum SolverMethod {
NewtonRaphson,
Brent,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum SolverStatus {
Converged,
NearExpiryIntrinsic,
NonPositivePrice,
BelowIntrinsic,
NoBracketInRange,
NotIdentifiable,
MaxIterations,
InvalidInput,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub struct SolverResult {
pub iv: f64,
pub method: SolverMethod,
pub iterations: u32,
pub converged: bool,
pub status: SolverStatus,
pub residual: f64,
}
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub struct InstrumentGreeks {
pub delta: f64,
pub gamma: f64,
pub vega: f64,
pub theta: f64,
pub rho: f64,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn option_type_display() {
assert_eq!(format!("{}", OptionType::Call), "Call");
assert_eq!(format!("{}", OptionType::Put), "Put");
}
#[test]
fn option_type_is_call() {
assert!(OptionType::Call.is_call());
assert!(!OptionType::Put.is_call());
}
}