use crate::{
core::{
instrument::{AssetClass, Instrument},
request::LegsProvider,
trade::{Side, Trade},
},
currencies::currency::Currency,
indices::marketindex::MarketIndex,
instruments::cashflows::leg::Leg,
time::date::Date,
};
pub struct Swap {
identifier: String,
legs: Vec<Leg>,
market_index: MarketIndex,
currency: Currency,
}
impl Swap {
#[must_use]
pub fn new(
identifier: String,
fixed_leg: Leg,
floating_leg: Leg,
market_index: MarketIndex,
currency: Currency,
) -> Self {
Self {
identifier,
legs: vec![fixed_leg, floating_leg],
market_index,
currency,
}
}
#[must_use]
pub fn fixed_leg(&self) -> &Leg {
&self.legs[0]
}
#[must_use]
pub fn floating_leg(&self) -> &Leg {
&self.legs[1]
}
#[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 Swap {
fn identifier(&self) -> String {
self.identifier.clone()
}
fn asset_class(&self) -> AssetClass {
AssetClass::InterestRate
}
}
impl LegsProvider for Swap {
fn legs(&self) -> &[Leg] {
&self.legs
}
}
pub struct SwapTrade {
instrument: Swap,
trade_date: Date,
notional: f64,
side: Side,
}
impl SwapTrade {
#[must_use]
pub const fn new(instrument: Swap, 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<Swap> for SwapTrade {
fn instrument(&self) -> &Swap {
&self.instrument
}
fn trade_date(&self) -> Date {
self.trade_date
}
fn side(&self) -> Side {
self.side
}
}
impl LegsProvider for SwapTrade {
fn legs(&self) -> &[Leg] {
self.instrument.legs()
}
}