Function amort_schedule

Source
pub fn amort_schedule(
    rate: Decimal,
    nper: u32,
    principal: Decimal,
    pmt: Decimal,
    round: Option<(u32, RoundingStrategy)>,
) -> Vec<AmortizationPeriod>
Expand description

Amortization Schedule

Calculates the amortization schedule for a loan or mortgage.

The amortization schedule includes a series of payments that are applied to both principal and interest. Each payment reduces the principal balance and pays interest charges based on the remaining balance and the interest rate.

§Feature

This function requires the std feature to be enabled as it uses std::Vec. amort_schedule_into can be used in no_std environments as any allocation is done by the caller.

§Arguments

  • rate - The interest rate per period
  • nper - The total number of payment periods
  • principal - The present value or principal amount of the loan (should be positive as cash inflow for a mortgage/loan)
  • pmt - The payment amount per period (should be negative as cash outflow, can be calculated using pmt function)
  • round (optional) - A tuple specifying the number of decimal places and a rounding strategy for the amounts (dp, RoundingStrategy), default is no rounding of calculations. The final principal payment is adjusted to zero out the remaining balance if rounding is enabled. rust_decimal::RoundingStrategy::MidpointNearestEven (“Bankers Rounding”) is likely what you are looking for

§Returns

  • A vector of AmortizationPeriod instances representing each period in the amortization schedule.

§Examples

  • 5% rate, 30 year term (360 months), $1,000,000 loan, $4,000 monthly payment
use rust_finprim::amort_dep_tax::amort_schedule;
use rust_decimal_macros::dec;
use rust_finprim::tvm::pmt;

let rate = dec!(0.05) / dec!(12);
let nper = 30 * 12;
let principal = dec!(1_000_000);
let pmt = pmt(rate, nper.into(), principal, None, None);

let schedule = amort_schedule(rate, nper, principal, pmt, None);