use crate::time::date::Date;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum OptionType {
#[default]
Call,
Put,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct EuropeanOption {
option_type: OptionType,
strike: f64,
maturity_date: Date,
}
impl EuropeanOption {
pub const fn new(option_type: OptionType, strike: f64, maturity_date: Date) -> Self {
Self {
option_type,
strike,
maturity_date,
}
}
pub const fn option_type(&self) -> OptionType {
self.option_type
}
pub const fn strike(&self) -> f64 {
self.strike
}
pub const fn maturity_date(&self) -> Date {
self.maturity_date
}
pub fn payoff(&self, spot: f64) -> f64 {
match self.option_type {
OptionType::Call => (spot - self.strike).max(0.0),
OptionType::Put => (self.strike - spot).max(0.0),
}
}
}