use serde::{Deserialize, Serialize};
use crate::{
core::{
instrument::{AssetClass, Instrument},
request::LegsProvider,
trade::{Side, Trade},
},
currencies::currency::Currency,
indices::marketindex::MarketIndex,
instruments::{cashflows::leg::Leg, rates::swap::Swap},
time::date::Date,
};
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub enum SwaptionExerciseType {
European,
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub enum SwaptionType {
Payer,
Receiver,
}
#[allow(clippy::struct_field_names)]
pub struct Swaption {
identifier: String,
underlying: Swap,
expiry: Date,
swaption_type: SwaptionType,
exercise_type: SwaptionExerciseType,
strike: f64,
market_index: MarketIndex,
currency: Currency,
}
impl Swaption {
#[must_use]
#[allow(clippy::too_many_arguments)]
pub const fn new(
identifier: String,
underlying: Swap,
expiry: Date,
swaption_type: SwaptionType,
exercise_type: SwaptionExerciseType,
strike: f64,
market_index: MarketIndex,
currency: Currency,
) -> Self {
Self {
identifier,
underlying,
expiry,
swaption_type,
exercise_type,
strike,
market_index,
currency,
}
}
#[must_use]
pub const fn underlying(&self) -> &Swap {
&self.underlying
}
#[must_use]
pub const fn expiry(&self) -> Date {
self.expiry
}
#[must_use]
pub const fn swaption_type(&self) -> SwaptionType {
self.swaption_type
}
#[must_use]
pub const fn exercise_type(&self) -> SwaptionExerciseType {
self.exercise_type
}
#[must_use]
pub const fn strike(&self) -> f64 {
self.strike
}
#[must_use]
pub fn market_index(&self) -> MarketIndex {
self.market_index.clone()
}
#[must_use]
pub const fn currency(&self) -> Currency {
self.currency
}
}
impl Instrument for Swaption {
fn identifier(&self) -> String {
self.identifier.clone()
}
fn asset_class(&self) -> AssetClass {
AssetClass::InterestRate
}
}
impl LegsProvider for Swaption {
fn legs(&self) -> &[Leg] {
self.underlying.legs()
}
}
pub struct SwaptionTrade {
instrument: Swaption,
trade_date: Date,
notional: f64,
side: Side,
}
impl SwaptionTrade {
#[must_use]
pub const fn new(
instrument: Swaption,
trade_date: Date,
notional: f64,
side: Side,
) -> Self {
Self {
instrument,
trade_date,
notional,
side,
}
}
#[must_use]
pub const fn notional(&self) -> f64 {
self.notional
}
}
impl Trade<Swaption> for SwaptionTrade {
fn instrument(&self) -> &Swaption {
&self.instrument
}
fn trade_date(&self) -> Date {
self.trade_date
}
fn side(&self) -> Side {
self.side
}
}
impl LegsProvider for SwaptionTrade {
fn legs(&self) -> &[Leg] {
self.instrument.legs()
}
}