use std::{cmp::Ordering, hash::Hash};
use serde::{Deserialize, Serialize};
use crate::utils::errors::QSError;
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub enum Strike {
Absolute(f64),
Atm,
Relative(f64),
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum VolatilityType {
Black,
Normal,
}
impl std::str::FromStr for VolatilityType {
type Err = QSError;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
match s {
"Black" => Ok(Self::Black),
"Normal" => Ok(Self::Normal),
_ => Err(QSError::InvalidValueErr(format!(
"Unknown volatility type: {s}"
))),
}
}
}
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
pub enum SmileType {
Strike,
Delta,
LogMoneyness,
}
#[derive(Clone, Debug, PartialEq)]
pub struct F64Key(pub f64);
impl F64Key {
#[must_use]
pub const fn new(value: f64) -> Self {
Self(value)
}
#[must_use]
pub const fn value(&self) -> f64 {
self.0
}
#[must_use]
pub const fn to_key(&self) -> u64 {
self.0.to_bits()
}
}
impl Eq for F64Key {}
impl PartialOrd for F64Key {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for F64Key {
fn cmp(&self, other: &Self) -> Ordering {
self.0.total_cmp(&other.0)
}
}
impl Hash for F64Key {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.to_key().hash(state);
}
}