2

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!

1
  • ` it only works for that example` - what does this mean? Please be specific, include all the info you have. Typing that something "doesn't work" isn't helpful. How does it not work? What was the input, what was the output and what was expected? Those three pieces of info are required so we can spot where the algorithm fails. Commented Aug 10, 2016 at 8:21

1 Answer 1

2

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));
Sign up to request clarification or add additional context in comments.

1 Comment

The USPV here is exactly the same that the one in your question. You changed (correctly, I presume) the way SPPV is calculated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.