use crate::Payoff;
use super::{BinaryType, OptionContract, TypeFlag};
#[derive(Debug, Clone)]
pub struct BinaryOption {
pub contract: OptionContract,
pub strike: f64,
pub binary_type: BinaryType,
}
impl Payoff for BinaryOption {
type Underlying = f64;
fn payoff(&self, underlying: Self::Underlying) -> f64 {
match self.binary_type {
BinaryType::CashOrNothing => match self.contract.type_flag {
TypeFlag::Call => match underlying > self.strike {
true => self.strike,
false => 0.0,
},
TypeFlag::Put => match underlying < self.strike {
true => self.strike,
false => 0.0,
},
},
BinaryType::AssetOrNothing => match self.contract.type_flag {
TypeFlag::Call => match underlying > self.strike {
true => underlying,
false => 0.0,
},
TypeFlag::Put => match underlying < self.strike {
true => underlying,
false => 0.0,
},
},
}
}
}