pub trait TimeExt {
fn tau(&self) -> Option<f64>;
fn eval(&self) -> Option<chrono::NaiveDate> {
None
}
fn expiration(&self) -> Option<chrono::NaiveDate> {
None
}
fn tau_or_from_dates(&self) -> f64 {
if let Some(tau) = self.tau() {
return tau;
}
match (self.eval(), self.expiration()) {
(Some(e), Some(x)) => crate::calendar::DayCountConvention::Actual365Fixed.year_fraction(e, x),
_ => f64::NAN,
}
}
fn tau_with_dcc(&self, dcc: crate::calendar::DayCountConvention) -> f64 {
if let Some(tau) = self.tau() {
return tau;
}
match (self.eval(), self.expiration()) {
(Some(e), Some(x)) => dcc.year_fraction(e, x),
_ => f64::NAN,
}
}
fn calculate_tau_in_years(&self) -> f64 {
self.tau_or_from_dates()
}
}