Skip to content

Instantly share code, notes, and snippets.

// This function calculates the Periodic Payment (PMT) of a loan.
// - rate: The interest rate per period (e.g., monthly interest rate for a monthly payment loan).
// - periods: The total number of payment periods.
// - value: The present value of the loan (amount borrowed).
// - future: The future value at the end of the loan (usually 0 for a loan).
// - ptype: Boolean indicating payment type (true for pay in advance, false for end of period).
func PMT(rate, periods, value, future float64, ptype bool) float64 {
var payment float64
if rate == 0 { // Handle special case: zero interest rate
payment = (value + future) / periods // Simple calculation for zero interest