rust_finprim/amort_dep_tax/structs.rs
1use rust_decimal::prelude::*;
2
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6/// Amorization Period
7///
8/// Represents a single period in an amortization schedule.
9///
10/// An amortization period includes information about the payment period, the portion
11/// of the payment allocated to principal, the portion allocated to interest, and the
12/// remaining balance of the loan or mortgage.
13#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
14#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
15pub struct AmortizationPeriod {
16 /// The period number of the amortization schedule.
17 pub period: u32,
18
19 /// The amount of the payment allocated to reduce the principal balance.
20 pub principal_payment: Decimal,
21
22 /// The amount of the payment allocated to pay interest charges.
23 pub interest_payment: Decimal,
24
25 /// The remaining balance of the loan or mortgage after the payment.
26 pub remaining_balance: Decimal,
27}
28
29impl AmortizationPeriod {
30 /// Creates a new `AmortizationPeriod` instance.
31 ///
32 /// # Arguments
33 /// * `period`: The period number of the amortization schedule.
34 /// * `principal_payment`: The amount allocated to reduce the principal balance.
35 /// * `interest_payment`: The amount allocated to pay interest charges.
36 /// * `remaining_balance`: The remaining balance of the loan or mortgage after the payment.
37 ///
38 /// # Returns
39 ///
40 /// A new `AmortizationPeriod` instance initialized with the provided values.
41 ///
42 /// # Examples
43 ///
44 /// ```
45 /// use rust_finprim::amort_dep_tax::AmortizationPeriod;
46 /// use rust_decimal_macros::*;
47 ///
48 /// let period = AmortizationPeriod::new(1, dec!(100), dec!(50), dec!(850));
49 /// ```
50 pub fn new(period: u32, principal_payment: Decimal, interest_payment: Decimal, remaining_balance: Decimal) -> Self {
51 Self {
52 period,
53 principal_payment,
54 interest_payment,
55 remaining_balance,
56 }
57 }
58}
59
60/// Depreciation Period
61///
62/// Represents a single period in an asset's depreciation schedule.
63///
64/// An asset depreciation period includes information about the period number,
65/// the depreciation expense for the period, and the remaining book value of the asset.
66/// The book value is the original cost of the asset minus the accumulated depreciation.
67///
68/// # Examples
69/// ```
70/// use rust_finprim::amort_dep_tax::DepreciationPeriod;
71/// use rust_decimal_macros::*;
72///
73/// let period = DepreciationPeriod::new(1, dec!(100), dec!(900));
74/// ```
75/// The above example creates a new `DepreciationPeriod` instance with a period number of 1,
76/// a depreciation expense of $100, and a remaining book value of $900.
77#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
78#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
79pub struct DepreciationPeriod {
80 /// The period number of the depreciation schedule.
81 pub period: u32,
82
83 /// The depreciation expense for the period.
84 pub depreciation_expense: Decimal,
85
86 /// The remaining book value of the asset.
87 pub remaining_book_value: Decimal,
88}
89
90impl DepreciationPeriod {
91 /// Creates a new `DepreciationPeriod` instance.
92 ///
93 /// # Arguments
94 /// * `period`: The period number of the depreciation schedule.
95 /// * `depreciation_expense`: The depreciation expense for the period.
96 /// * `remaining_book_value`: The remaining book value of the asset.
97 ///
98 /// # Returns
99 ///
100 /// A new `DepreciationPeriod` instance initialized with the provided values.
101 pub fn new(period: u32, depreciation_expense: Decimal, remaining_book_value: Decimal) -> Self {
102 Self {
103 period,
104 depreciation_expense,
105 remaining_book_value,
106 }
107 }
108}