use serde::{Deserialize, Serialize};
use crate::{
indices::marketindex::MarketIndex,
time::{daycounter::DayCounter, enums::Frequency, period::Period},
volatility::volatilitysource::VolatilitySourceConfiguration,
};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum ModelConfiguration {
HullWhite {
alpha: f64,
volatility: VolatilitySourceConfiguration,
},
BrownianMotion {
volatility: VolatilitySourceConfiguration,
#[serde(default)]
dividend_rate: Option<f64>,
},
Lgm {
lambda: f64,
volatility: VolatilitySourceConfiguration,
},
}
const fn default_n_paths() -> usize {
1000
}
const fn default_seed() -> u64 {
42
}
const fn default_frequency() -> Frequency {
Frequency::Monthly
}
const fn default_day_counter() -> DayCounter {
DayCounter::Actual365
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SimulationConfiguration {
market_index: MarketIndex,
model: ModelConfiguration,
#[serde(default = "default_n_paths")]
n_paths: usize,
#[serde(default = "default_seed")]
seed: u64,
horizon: Period,
#[serde(default = "default_frequency")]
frequency: Frequency,
#[serde(default = "default_day_counter")]
day_counter: DayCounter,
}
impl SimulationConfiguration {
#[must_use]
pub const fn new(
market_index: MarketIndex,
model: ModelConfiguration,
n_paths: usize,
seed: u64,
horizon: Period,
frequency: Frequency,
) -> Self {
Self {
market_index,
model,
n_paths,
seed,
horizon,
frequency,
day_counter: DayCounter::Actual365,
}
}
#[must_use]
pub const fn market_index(&self) -> &MarketIndex {
&self.market_index
}
#[must_use]
pub const fn model(&self) -> &ModelConfiguration {
&self.model
}
#[must_use]
pub const fn n_paths(&self) -> usize {
self.n_paths
}
#[must_use]
pub const fn seed(&self) -> u64 {
self.seed
}
#[must_use]
pub const fn horizon(&self) -> Period {
self.horizon
}
#[must_use]
pub const fn frequency(&self) -> Frequency {
self.frequency
}
#[must_use]
pub const fn day_counter(&self) -> DayCounter {
self.day_counter
}
}