Recent

Author Topic: Math's payment function is ... wrong? (or is it me?)  (Read 835 times)

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 348
  • My software never cras....
Math's payment function is ... wrong? (or is it me?)
« on: October 27, 2019, 10:23:58 pm »
I wrote a routine to compare instalment payments but the value returned by Math.Payment is off by 16 cents v. Excel (or v. my actual car payment calculated by Honda...)

So I wrote my own function and it is bang on with Excel and Honda.
Code: Pascal  [Select][+][-]
  1. Function Payment1 (amt: real; rate:real; years:word; PperYear:word):double;
  2. VAR
  3.         rpp: double;
  4. BEGIN
  5.         rpp := rate/PperYear;  
  6.         Payment1 := -amt * rpp / (1-Power(1+rpp,-years*PperYear));
  7. END;
  8.  

Call:
Code: Pascal  [Select][+][-]
  1. Pmt := -Payment1(Cap,Rate,Yrs,PPY);


How I call the Math.Payment:
Code: Pascal  [Select][+][-]
  1. Pmt := -Payment(Rate/PPY, Yrs*PPY, Cap, 0, ptstartofperiod)

Where rate is 0.0199, PPY is 26, Yrs is 3, Cap is 15904.20, 0 is 0 (!), ...

Correct result (Excel, Honda and my function) = 203.90.

Math.Payment result = 203.74.

... anyway I'll stick with my function for now...

Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Math's payment function is ... wrong? (or is it me?)
« Reply #1 on: October 27, 2019, 10:57:59 pm »
Something is wrong with your numbers -- they yield payments like 210, instead of 204.

You must be careful with the last parameter of the function which you inserted as ptStartOfPeriod. This means that interest is deducted from the remaining debts immediately when you make the payment. As a consequence the debts are reducing a bit faster and you pay a bit less interest than when interest is deducted at the end of the payment period. This is not what the car dealer wants and he will usually give you a credit with ptEndOfPeriod conditions. And this is what Excel inserts for this parameter by default.

The following program
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. uses
  4.   Math;
  5. const
  6.   Rate = 0.0199;
  7.   PPY = 26;
  8.   Yrs = 3;
  9.   Cap = 15904.20;
  10. begin
  11.   WriteLn('ptStartOfPeriod: ', Payment(rate/PPY, yrs*PPY, Cap, 0, ptStartOfPeriod):0:2);
  12.   WriteLn('  ptEndOfPeriod: ', Payment(rate/PPY, yrs*PPY, Cap, 0, ptEndOfPeriod):0:2);
  13. end.
has this output:
Quote
ptStartOfPeriod: -209.96
ptEndOfPeriod: -210.12

The attached screenshot of Excel shows the same results. Note that in both cases the rate to be payed by you is higher when your payment is accounted at the end of the payment period although the interest rate is the same...

So, nothing's wrong with our Payment() function.

P.S.
I don't know why you put an exclamation mark after the 0. This is the "future value", i.e. the remaining amount to be paid after the 3 years. Of course, you want to be finished then, and the future value must be zero.
« Last Edit: October 27, 2019, 11:56:11 pm by wp »

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 348
  • My software never cras....
Re: Math's payment function is ... wrong? (or is it me?)
« Reply #2 on: October 27, 2019, 11:05:25 pm »
 :-[

Oddly when I was writing it originally I had it at 'end' not start.  But chasing another bug I set it to 'start'.

Thanks.  Now agrees perfectly. Yes: the capital amount should have been 15432.87, not 15904.20.

Cheers,

PSR: (!) just as an obvious as most consumer loans for things like cars are to bring the loan value to 0.  Not an area where balloon payments occur - perhaps exotic cars go that way though...
« Last Edit: October 27, 2019, 11:07:31 pm by AlanTheBeast »
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

 

TinyPortal © 2005-2018