use crate::OptionType;
pub trait PricerExt: super::time::TimeExt {
fn calculate_call_put(&self) -> (f64, f64);
fn calculate_price(&self) -> f64;
fn derivatives(&self) -> Vec<f64> {
vec![]
}
fn implied_volatility(&self, _c_price: f64, _option_type: OptionType) -> f64 {
0.0
}
}
pub trait ModelPricer {
fn price_call(&self, s: f64, k: f64, r: f64, q: f64, tau: f64) -> f64;
fn price_put(&self, s: f64, k: f64, r: f64, q: f64, tau: f64) -> f64 {
let call = self.price_call(s, k, r, q, tau);
call - s * (-q * tau).exp() + k * (-r * tau).exp()
}
fn price_option(&self, s: f64, k: f64, r: f64, q: f64, tau: f64, option_type: OptionType) -> f64 {
match option_type {
OptionType::Call => self.price_call(s, k, r, q, tau),
OptionType::Put => self.price_put(s, k, r, q, tau),
}
}
}
pub trait GreeksExt {
fn delta(&self) -> f64;
fn gamma(&self) -> f64 {
f64::NAN
}
fn vega(&self) -> f64 {
f64::NAN
}
fn theta(&self) -> f64 {
f64::NAN
}
fn rho(&self) -> f64 {
f64::NAN
}
}