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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
//! The interest change definition of an event.
// Copyright (c) 2021 ShiftLeft Software
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use rust_decimal::prelude::*;
pub struct ElemInterestChange {
/// Interest method used.
method: crate::MethodType,
/// Day count basis.
day_count_basis: crate::DayCountType,
/// Number of days in the year.
days_in_year: usize,
/// Optional effective frequency.
effective_frequency: crate::FrequencyType,
/// Optional interest amortization frequency.
interest_frequency: crate::FrequencyType,
/// Round intermediate balance results.
round_balance: crate::RoundType,
/// Less than zero: Use preferences
/// Greater than zero and less than one: Round to fraction
/// Zero or greater than and equal to one: Decimal digits to round.
round_decimal_digits: Decimal,
}
/// The interest change implementation.
impl ElemInterestChange {
/// Create a new interest change element.
///
/// # Arguments
///
/// * `method_param` - Interest method.
/// * `day_count_basis_param` - Day count basis.
/// * `days_in_year_param` - Days in year.
/// * `effective_frequency_param` - Optional effective frequency.
/// * `interest_frequency_param` - Optional interest amortization frequency.
/// * `round_balance_param` - Round balance.
/// * `round_decimal_digits_param` - Round decimal digits.
///
/// # Return
///
/// * See description.
pub fn new(
method_param: crate::MethodType,
day_count_basis_param: crate::DayCountType,
days_in_year_param: usize,
effective_frequency_param: crate::FrequencyType,
interest_frequency_param: crate::FrequencyType,
round_balance_param: crate::RoundType,
round_decimal_digits_param: Decimal,
) -> ElemInterestChange {
ElemInterestChange {
method: method_param,
day_count_basis: day_count_basis_param,
days_in_year: days_in_year_param,
effective_frequency: effective_frequency_param,
interest_frequency: interest_frequency_param,
round_balance: round_balance_param,
round_decimal_digits: round_decimal_digits_param,
}
}
/// Copy this interest change element as a new interest change element.
///
/// # Return
///
/// * See description.
pub fn copy(&self) -> ElemInterestChange {
ElemInterestChange::new(
self.method,
self.day_count_basis,
self.days_in_year,
self.effective_frequency,
self.interest_frequency,
self.round_balance,
self.round_decimal_digits,
)
}
/// Tests if this interest change object and another are equal.
///
/// # Arguments
///
/// * `elem_interest_change` - Object to compare.
/// # Return
///
/// * True if equals, otherwise false.
pub fn equal(&self, elem_interest_change: &ElemInterestChange) -> bool {
self.method == elem_interest_change.method
&& self.day_count_basis == elem_interest_change.day_count_basis
&& self.days_in_year == elem_interest_change.days_in_year
&& self.effective_frequency == elem_interest_change.effective_frequency
&& self.interest_frequency == elem_interest_change.interest_frequency
&& self.round_balance == elem_interest_change.round_balance
&& self.round_decimal_digits == elem_interest_change.round_decimal_digits
}
/// Get the interest method used.
///
/// # Return
///
/// * See description.
///
pub fn method(&self) -> crate::MethodType {
self.method
}
/// Get the day count basis.
///
/// # Return
///
/// * See description.
pub fn day_count_basis(&self) -> crate::DayCountType {
self.day_count_basis
}
/// Get the number of days in the year.
///
/// # Return
///
/// * See description.
pub fn days_in_year(&self) -> usize {
self.days_in_year
}
/// Get the optional effective frequency.
///
/// # Return
///
/// * See description.
///
pub fn effective_frequency(&self) -> crate::FrequencyType {
self.effective_frequency
}
/// Get the optional interest amortization frequency.
///
/// # Return
///
/// * See description.
///
pub fn interest_frequency(&self) -> crate::FrequencyType {
self.interest_frequency
}
/// Get the round intermediate balance results.
///
/// # Return
///
/// * See description.
///
pub fn round_balance(&self) -> crate::RoundType {
self.round_balance
}
/// Get the round decimal digits.
///
/// # Return
///
/// * See description.
///
pub fn round_decimal_digits(&self) -> Decimal {
self.round_decimal_digits
}
/// Set the interest method used.
///
/// # Arguments
///
/// * `method_param` - See description.
///
pub fn set_method(&mut self, method_param: crate::MethodType) {
self.method = method_param;
}
/// Set the day count basis.
///
/// # Arguments
///
/// * `day_count_basis_param` - See description.
///
pub fn set_day_count_basis(&mut self, day_count_basis_param: crate::DayCountType) {
self.day_count_basis = day_count_basis_param;
}
/// Set the number of days in the year.
///
/// # Arguments
///
/// * `days_in_year_param` - See description.
pub fn set_days_in_year(&mut self, days_in_year_param: usize) {
self.days_in_year = days_in_year_param;
}
/// Set the optional effective frequency.
///
/// # Arguments
///
/// * `effective_frequency_param` - See description.
///
pub fn set_effective_frequency(&mut self, effective_frequency_param: crate::FrequencyType) {
self.effective_frequency = effective_frequency_param;
}
/// Set the optional interest amortization frequency.
///
/// # Arguments
///
/// * `interest_frequency_param` - See description.
///
pub fn set_interest_frequency(&mut self, interest_frequency_param: crate::FrequencyType) {
self.interest_frequency = interest_frequency_param;
}
/// Set the round intermediate balance results.
///
/// # Arguments
///
/// * `round_balance_param` - See description.
///
pub fn set_round_balance(&mut self, round_balance_param: crate::RoundType) {
self.round_balance = round_balance_param;
}
/// Set the round decimal digits.
///
/// # Arguments
///
/// * `round_decimal_digits_param` - See description.
///
pub fn set_round_decimal_digits(&mut self, round_decimal_digits_param: Decimal) {
self.round_decimal_digits = round_decimal_digits_param;
}
}