loan
Types
pub type Loan {
Loan(
initial_principal: Int,
remaining_principal: Int,
interest: Float,
term: Int,
period: Int,
)
}
Constructors
-
Loan( initial_principal: Int, remaining_principal: Int, interest: Float, term: Int, period: Int, )
Arguments
-
initial_principal
amount of the loan in cents at the start of the loan
-
remaining_principal
amount of the loan in cents that currently remain
-
interest
annual interest rate
-
term
number of individual payments to be made over the life of the loan
-
period
number of payments in a period for which to apply interest e.g. 12 for monthly e.g. 4 for quarterly
-
pub type ScheduleItem {
ScheduleItem(
payment_number: Int,
payment_amount: Int,
interest_payment: Int,
principal_payment: Int,
remaining_principal: Int,
)
}
Constructors
-
ScheduleItem( payment_number: Int, payment_amount: Int, interest_payment: Int, principal_payment: Int, remaining_principal: Int, )
Arguments
-
payment_number
the payment number
-
payment_amount
the amount of the payment in cents
-
interest_payment
the amount of the payment that goes to interest in cents
-
principal_payment
the amount of the payment that goes to principal in cents
-
remaining_principal
the remaining principal balance of the loan in cents
-
Functions
pub fn amortization_schedule(
loan: Loan,
) -> Result(List(ScheduleItem), Nil)
Calculate the amortization schedule for a loan
pub fn amortized_payment(loan: Loan) -> Result(Int, Nil)
Calculate the individual amortized payment for a loan
Returns the amortized payment in cents
pub fn interest_payment(loan: Loan) -> Int
Calculate the interest payment for a loan
Returns the interest payment in cents
pub fn total_interest_paid(loan: Loan) -> Int
pub fn total_paid(loan: Loan) -> Int