1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use crate::{
ad::adreal::ADReal,
core::{collateral::HasCurrency, trade::Side},
currencies::currency::Currency,
indices::marketindex::MarketIndex,
instruments::cashflows::cashflowtype::CashflowType,
rates::interestrate::InterestRate,
time::date::Date,
};
/// A [`Leg`] represents a sequence of cashflows associated to a particular instrument.
pub struct Leg {
/// identifier for the leg, used for referencing in pricers and other components
id: usize,
/// list of cashflows associated with the leg
cashflows: Vec<CashflowType>,
/// currency of the cashflows
currency: Currency,
/// forward rate index, if required
market_index: Option<MarketIndex>,
/// spread of the floating leg, if any
spread: Option<ADReal>,
/// rate associated with fixed-rate cashflows, if any
interest_rate: Option<InterestRate<ADReal>>,
/// side of the leg (long or short)
side: Side,
/// whether the leg has a linear payoff structure (e.g., fixed payments) or non-linear (e.g., options)
is_linear: bool,
/// optional first and last payment dates for the leg, used for optimization and curve bootstrapping
first_payment_date: Date,
/// optional last payment date for the leg, used for optimization and curve bootstrapping
last_payment_date: Date,
}
impl Leg {
/// Creates a new [`Leg`] with the specified parameters.
#[must_use]
#[allow(clippy::too_many_arguments)]
pub const fn new(
id: usize,
cashflows: Vec<CashflowType>,
currency: Currency,
market_index: Option<MarketIndex>,
spread: Option<ADReal>,
interest_rate: Option<InterestRate<ADReal>>,
side: Side,
is_linear: bool,
first_payment_date: Date,
last_payment_date: Date,
) -> Self {
Self {
id,
cashflows,
currency,
market_index,
spread,
interest_rate,
side,
is_linear,
first_payment_date,
last_payment_date,
}
}
/// Returns the identifier of the leg.
#[must_use]
pub const fn id(&self) -> usize {
self.id
}
/// Returns the cashflows associated with the leg.
#[must_use]
pub fn cashflows(&self) -> &[CashflowType] {
&self.cashflows
}
/// Returns the market index associated with the leg, if any.
#[must_use]
pub const fn market_index(&self) -> Option<&MarketIndex> {
self.market_index.as_ref()
}
/// Returns the spread associated with the leg, if any.
#[must_use]
pub const fn spread(&self) -> Option<ADReal> {
self.spread
}
/// Returns the interest rate associated with the leg, if any.
#[must_use]
pub const fn interest_rate(&self) -> Option<InterestRate<ADReal>> {
self.interest_rate
}
/// Returns the side of the leg (long or short).
#[must_use]
pub const fn side(&self) -> Side {
self.side
}
/// Returns whether the leg is linear (i.e., has a linear payoff structure) or non-linear.
#[must_use]
pub const fn is_linear(&self) -> bool {
self.is_linear
}
/// Returns the first payment date of the leg.
#[must_use]
pub const fn first_payment_date(&self) -> Date {
self.first_payment_date
}
/// Returns the last payment date of the leg.
#[must_use]
pub const fn last_payment_date(&self) -> Date {
self.last_payment_date
}
}
impl HasCurrency for Leg {
fn currency(&self) -> Currency {
self.currency
}
}