HP Forums
HP Prime: Length of a Loan with a Certain Payment - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP Prime Software Library (/forum-15.html)
+--- Thread: HP Prime: Length of a Loan with a Certain Payment (/thread-10394.html)



HP Prime: Length of a Loan with a Certain Payment - Eddie W. Shore - 03-26-2018 01:49 PM

Introduction

The program PMTLENGTH will calculate how many payments that are required to finish a loan, given a certain annual interest rate and payment. Payments are assumed to be monthly, and end of period. The program will also return the last payment. Due to the rounding in the financial algorithms, the last payment is an approximate (unless the interest rate is 0%).

Input: PMTLENGTH(I,P,X)
I = annual interest rate
P = loan amount
X = payment amount, enter as a negative amount

Firmware 13441 or later is required.


HP Prime Program PMTLENGTH

Code:
EXPORT PMTLENGTH(I,P,X)
BEGIN
// I%YR, PV, PMT (as negative)
// 2018-03-19 EWS
// how many monthly payments?
// last payment? (FV)

LOCAL N,B;

N:=Finance.TvmNbPmt(I,P,X,0,12);
B:=P;
IF FP(N)≠0 THEN
B:=Finance.TvmFV(IP(N),I,P,X,12);
N:=IP(N)+1;
END;

// {N, final pmt}
RETURN {N,B};
END;

Examples

Example 1: How long will I take to pay off a $2,000 loan if I make $600 payments each month? This is a no interest loan.

Result: {4, -200}

It will take 4 payments, with the last payment being $200.

Example 2: How long will I take to pay off a $5,350 loan if I make $750 monthly payments each month? The loan has a 10% monthly interest rate.

Result: {8, -286.906502677}

It will take 8 payments, with the last payment being about $286.91.


RE: HP Prime: Length of a Loan with a Certain Payment - Komanguy - 07-28-2018 08:27 PM

Thanks a lot for this useful program.

I’m a new hp prime user and it’s a good example on how financial functions works.