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