use std::cell::{Ref, RefMut};
use crate::{
ad::adreal::ADReal,
core::{marketdatahandling::constructedelementstore::SharedElement, pillars::Pillars},
currencies::currency::Currency,
indices::marketindex::MarketIndex,
rates::yieldtermstructure::interestratestermstructure::InterestRatesTermStructure,
};
pub trait ADCurveElement:
InterestRatesTermStructure<ADReal> + Pillars<ADReal> + Send + Sync
{
}
#[derive(Clone)]
pub struct DiscountCurveElement {
market_index: MarketIndex,
currency: Currency,
curve: SharedElement<dyn ADCurveElement>,
}
impl DiscountCurveElement {
#[must_use]
pub const fn new(
market_index: MarketIndex,
currency: Currency,
curve: SharedElement<dyn ADCurveElement>,
) -> Self {
Self {
market_index,
currency,
curve,
}
}
#[must_use]
pub const fn market_index(&self) -> &MarketIndex {
&self.market_index
}
#[must_use]
pub const fn currency(&self) -> Currency {
self.currency
}
#[must_use]
pub fn curve(&self) -> Ref<'_, dyn ADCurveElement> {
self.curve.borrow()
}
#[must_use]
pub fn curve_mut(&mut self) -> RefMut<'_, dyn ADCurveElement> {
self.curve.borrow_mut()
}
}
#[derive(Clone)]
pub struct DividendCurveElement {
market_index: MarketIndex,
currency: Currency,
curve: SharedElement<dyn ADCurveElement>,
}
impl DividendCurveElement {
#[must_use]
pub const fn new(
market_index: MarketIndex,
currency: Currency,
curve: SharedElement<dyn ADCurveElement>,
) -> Self {
Self {
market_index,
currency,
curve,
}
}
#[must_use]
pub const fn market_index(&self) -> &MarketIndex {
&self.market_index
}
#[must_use]
pub const fn currency(&self) -> &Currency {
&self.currency
}
#[must_use]
pub fn curve(&self) -> Ref<'_, dyn ADCurveElement> {
self.curve.borrow()
}
#[must_use]
pub fn curve_mut(&mut self) -> RefMut<'_, dyn ADCurveElement> {
self.curve.borrow_mut()
}
}