use crate::{
currencies::enums::Currency,
rates::enums::Compounding,
time::{date::Date, enums::Frequency},
utils::errors::{AtlasError, Result},
};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ExchangeRateRequest {
first_currency: Currency,
second_currency: Option<Currency>,
reference_date: Option<Date>,
}
impl ExchangeRateRequest {
#[must_use]
pub const fn new(
first_currency: Currency,
second_currency: Option<Currency>,
reference_date: Option<Date>,
) -> Self {
Self {
first_currency,
second_currency,
reference_date,
}
}
#[must_use]
pub const fn first_currency(&self) -> Currency {
self.first_currency
}
#[must_use]
pub const fn second_currency(&self) -> Option<Currency> {
self.second_currency
}
#[must_use]
pub const fn reference_date(&self) -> Option<Date> {
self.reference_date
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DiscountFactorRequest {
provider_id: usize,
date: Date,
}
impl DiscountFactorRequest {
#[must_use]
pub const fn new(provider_id: usize, date: Date) -> Self {
Self { provider_id, date }
}
#[must_use]
pub const fn provider_id(&self) -> usize {
self.provider_id
}
#[must_use]
pub const fn date(&self) -> Date {
self.date
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ForwardRateRequest {
provider_id: usize,
fixing_date: Date,
start_date: Date,
end_date: Date,
compounding: Compounding,
frequency: Frequency,
}
impl ForwardRateRequest {
#[must_use]
pub const fn new(
provider_id: usize,
fixing_date: Date,
start_date: Date,
end_date: Date,
compounding: Compounding,
frequency: Frequency,
) -> Self {
Self {
provider_id,
fixing_date,
start_date,
end_date,
compounding,
frequency,
}
}
#[must_use]
pub const fn provider_id(&self) -> usize {
self.provider_id
}
#[must_use]
pub const fn start_date(&self) -> Date {
self.start_date
}
#[must_use]
pub const fn end_date(&self) -> Date {
self.end_date
}
#[must_use]
pub const fn compounding(&self) -> Compounding {
self.compounding
}
#[must_use]
pub const fn frequency(&self) -> Frequency {
self.frequency
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MarketRequest {
id: usize,
df: Option<DiscountFactorRequest>,
fwd: Option<ForwardRateRequest>,
fx: Option<ExchangeRateRequest>,
}
impl MarketRequest {
#[must_use]
pub const fn new(
id: usize,
df: Option<DiscountFactorRequest>,
fwd: Option<ForwardRateRequest>,
fx: Option<ExchangeRateRequest>,
) -> Self {
Self { id, df, fwd, fx }
}
#[must_use]
pub const fn id(&self) -> usize {
self.id
}
#[must_use]
pub const fn df(&self) -> Option<DiscountFactorRequest> {
self.df
}
#[must_use]
pub const fn fwd(&self) -> Option<ForwardRateRequest> {
self.fwd
}
#[must_use]
pub const fn fx(&self) -> Option<ExchangeRateRequest> {
self.fx
}
}
#[derive(Debug, Clone, Copy)]
pub struct MarketData {
id: usize,
reference_date: Date,
df: Option<f64>,
fwd: Option<f64>,
fx: Option<f64>,
numerarie: f64,
}
impl MarketData {
#[must_use]
pub const fn new(
id: usize,
reference_date: Date,
df: Option<f64>,
fwd: Option<f64>,
fx: Option<f64>,
numerarie: f64,
) -> Self {
Self {
id,
reference_date,
df,
fwd,
fx,
numerarie,
}
}
#[must_use]
pub const fn id(&self) -> usize {
self.id
}
#[must_use]
pub const fn reference_date(&self) -> Date {
self.reference_date
}
pub fn df(&self) -> Result<f64> {
self.df.ok_or(AtlasError::ValueNotSetErr("df".to_owned()))
}
pub fn fwd(&self) -> Result<f64> {
self.fwd.ok_or(AtlasError::ValueNotSetErr("fwd".to_owned()))
}
pub fn fx(&self) -> Result<f64> {
self.fx.ok_or(AtlasError::ValueNotSetErr("fx".to_owned()))
}
#[must_use]
pub const fn numerarie(&self) -> f64 {
self.numerarie
}
}