use crate::Moneyness;
use crate::OptionType;
#[derive(Debug, Clone)]
pub struct DeltaHedge {
pub c: f64,
pub c_premium: f64,
pub c_delta: f64,
pub k: f64,
pub s: f64,
pub s0: f64,
pub contract_size: f64,
pub hedge_size: f64,
pub option_type: OptionType,
pub dotm_threshold: f64,
pub ditm_threshold: f64,
pub atm_threshold: f64,
pub itm_threshold: f64,
}
impl DeltaHedge {
#[allow(clippy::too_many_arguments)]
pub fn new(
c: f64,
c_premium: f64,
c_delta: f64,
k: f64,
s: f64,
s0: f64,
contract_size: f64,
hedge_size: f64,
option_type: OptionType,
dotm_threshold: f64,
ditm_threshold: f64,
atm_threshold: f64,
itm_threshold: f64,
) -> Self {
Self {
c,
c_premium,
c_delta,
k,
s,
s0,
contract_size,
hedge_size,
option_type,
dotm_threshold,
ditm_threshold,
atm_threshold,
itm_threshold,
}
}
}
impl DeltaHedge {
pub fn hedge_cost(&self) -> f64 {
self.hedge_shares() * self.s - (self.c_premium * self.contract_size)
}
pub fn current_hedge_profit(&self) -> f64 {
let option_profit = (self.c_premium - self.c) * self.contract_size;
let stock_profit = (self.s - self.s0) * self.hedge_shares();
option_profit + stock_profit
}
pub fn hedge_shares(&self) -> f64 {
self.c_delta * self.contract_size
}
pub fn moneyness(&self) -> Moneyness {
let moneyness_ratio = match self.option_type {
OptionType::Call => self.s / self.k,
OptionType::Put => self.k / self.s,
};
if moneyness_ratio > self.ditm_threshold {
Moneyness::DeepInTheMoney
} else if moneyness_ratio > 1.0 {
Moneyness::InTheMoney
} else if (moneyness_ratio - self.itm_threshold).abs() <= (1.0 - self.atm_threshold) {
Moneyness::AtTheMoney
} else if moneyness_ratio < self.dotm_threshold {
Moneyness::DeepOutOfTheMoney
} else {
Moneyness::OutOfTheMoney
}
}
}