use serde::{Deserialize, Serialize};
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct OptionGreeks {
pub delta: Option<f64>,
pub gamma: Option<f64>,
pub theta: Option<f64>,
pub vega: Option<f64>,
pub implied_volatility: Option<f64>,
pub theoretical_price: Option<f64>,
pub underlying_price: Option<f64>,
}
impl OptionGreeks {
pub fn has_any_greek(&self) -> bool {
self.delta.is_some()
|| self.gamma.is_some()
|| self.theta.is_some()
|| self.vega.is_some()
|| self.implied_volatility.is_some()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn option_greeks_default_has_no_values() {
let greeks = OptionGreeks::default();
assert!(!greeks.has_any_greek());
}
#[test]
fn option_greeks_partial_has_any_greek() {
let greeks = OptionGreeks {
delta: Some(0.55),
..Default::default()
};
assert!(greeks.has_any_greek());
}
#[test]
fn option_greeks_full_has_any_greek() {
let greeks = OptionGreeks {
delta: Some(0.55),
gamma: Some(0.02),
theta: Some(-0.05),
vega: Some(0.15),
implied_volatility: Some(0.25),
theoretical_price: Some(5.50),
underlying_price: Some(150.0),
};
assert!(greeks.has_any_greek());
}
#[test]
fn option_greeks_price_only_has_no_greek() {
let greeks = OptionGreeks {
theoretical_price: Some(5.50),
underlying_price: Some(150.0),
..Default::default()
};
assert!(!greeks.has_any_greek());
}
}