I am trying to rebuild the Excel formula "Rate" in APEX. This is a formula for calculating the interest percentage of a loan, based on the number of periods, payment amount and total amount.
It's obviously not possible in a formula field because it involves an iterative process for guessing the percentage and then trying to get closer to it in each step.
This is the definition of the Rate function:
RATE(nper, pmt, pv, [fv], [type], [guess])
- Nper Required. The total number of payment periods in an annuity.
- Pmt Required. The payment made each period and cannot change over the life of the annuity. Typically, pmt includes principal and interest but no other fees or taxes. If pmt is omitted, you must include the fv argument.
- Pv Required. The present value — the total amount that a series of future payments is worth now.
- Fv Optional. The future value, or a cash balance you want to attain after the last payment is made. If fv is omitted, it is assumed to be 0 (the future value of a loan, for example, is 0).
- Type Optional. The number 0 or 1 and indicates when payments are due.
- guess Optional. Your guess of what the rate will be