Reputation: 581
I have an advanced PMT calculation to make. I have been given an example to work through, and whilst the code will give me the correct answer it only works for that example.
I am using the HP 17bII calculator to verify my results, which need to be the same.
Present Value: PV - -1000
Future Value: FV - 0
Interest Rate: IYR - 8
Frequency: FREQ - 12
Number of Payments: N - 60
Advance no. of Payments: ADV - 3
These are the values and the expected result, which is the PMT is 19.88.
In the formulae for the calculator the function calls two other functions, SPPV and USPV. There are worked out below.
PV = -10000; //Present Value
FV = 0; //Future Value
IYR = 8; //Interest Rate
FREQ = 12; //Payment Frequency
ADV = 3; //No. of advance payments
TERM = 57; //Term of the Loan
N = 57 + 3; //The N is the sum of ADV + TERM
SIR = IYR / FREQ; //Interest rate for the SPPV var
UIR = (IYR / 100) / FREQ; //Interest rate for the USPV
SPPV = (1 / (Math.pow(((1 + SIR) / 100), N)));
USPV = (Math.pow((1 + UIR), TERM) - 1)/(UIR*Math.pow((1+UIR), TERM));
PMT = Math.abs((PV - FV * SPPV)/(USPV + ADV));
Any help at all would be greatly appreciated. Sorry if this is a duplicate or otherwise, I have searched extensively.
Thanks!
Upvotes: 2
Views: 1007
Reputation: 581
I found out where I was going wrong. This is my updated code. It was a matter of switching TERM in the USPV var for N. I feel so silly.
SIR = IYR / FREQ;
UIR = (IYR / 100) / FREQ;
N = ADV + TERM;
SPPV = 1 / (Math.pow((1 + (SIR / 100)), N));
USPV = (Math.pow(1 + UIR, TERM) - 1) / (UIR * (Math.pow(1 + UIR, TERM)));
PMT = Math.abs((PV - FV * SPPV) / (USPV + ADV));
Upvotes: 2