This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 |