use std::cell::Ref;
use crate::{
ad::dual::DualFwd,
core::elements::volatilitysurfaceelement::{ADVolatilitySurfaceElement, VolatilitySurfaceElement},
utils::errors::Result,
};
pub struct OrientedFxVolSurface<'a> {
element: &'a VolatilitySurfaceElement,
inverted: bool,
}
impl<'a> OrientedFxVolSurface<'a> {
#[must_use]
pub const fn new(element: &'a VolatilitySurfaceElement, inverted: bool) -> Self {
Self { element, inverted }
}
#[must_use]
pub const fn element(&self) -> &'a VolatilitySurfaceElement {
self.element
}
#[must_use]
pub const fn is_inverted(&self) -> bool {
self.inverted
}
#[must_use]
pub fn surface(&self) -> Ref<'_, dyn ADVolatilitySurfaceElement> {
self.element.surface()
}
pub fn volatility_from_date(
&self,
expiry: crate::time::date::Date,
strike: f64,
) -> Result<DualFwd> {
let key = if self.inverted { 1.0 / strike } else { strike };
self.element.surface().volatility_from_date(expiry, key)
}
}