[net.misc] Calculating loan payments

murray@t4test.UUCP (Murray Lane) (02/17/84)

I have seen several articles here and there (most recently in net.sources
(what an odd place)) asking how to calculate monthly installment loan 
payments. I wrote a program some years back that does exactly that (in
Pascal) and (logicly enough) had to find out how to do the calculation.
The following formula does it, It is quite accurate (the last payment
always leaves a balance of $0.00 +/- $0.01). I have compared it against
loans I have received from lending institutions and the numbers come
out the same if you add in some fudge factors (extra charges the bank
hides in your payment (cost of setting up the loan, etc)). If anyone is
interested, I'll mail them the source, or if there is a lot of interest
(no pun intended), I'll post it to net.sources. In any case, don't be
in any hurry, we have terrible UUCP troubles here and only get on the
net about once a week.


		P=A((i(1+i)^n)/((1+i)^n-1))

	where P is the monthly payment;
	      A is the initial loan amount;
	      i is the monthly intrest rate (annual/12);
	 and  n is the number of months.

The balance can also be computed by the formula:

		B=A(1+i)^n-P(((1+i)^n-1)/i)

	where B is the remaining principal after n months.

andrew@inmet.UUCP (03/04/84)

#N:inmet:6400096:000:430
inmet!andrew    Mar  1 12:04:00 1984

The first response to this is a C program to calculate loan payments.  It
takes three command line arguments:  Amount borrowed ($), interest rate (%)
and term of loan (years).

This is extracted from a much longer program which prints out a complete
amortization table, including YTD interest for tax purposes.  I'll send
that one to anyone who requests it.
 
Andrew W. Rogers, Intermetrics    ...{harpo|ima|esquire}!inmet!andrew

andrew@inmet.UUCP (03/04/84)

#R:inmet:6400096:inmet:6400097:000:804
inmet!andrew    Mar  1 12:07:00 1984

main(argc, argv)        /* Calculate loan payments */
int argc;
char *argv[];

{
float loan_amount, yearly_rate;	
double monthly_rate, x, y;
int term_years, term_months, i;
long payment;

if (argc < 3) {
    printf("usage: %s amount($) rate(%%) years\n", argv[0]);
    return;
    }
sscanf(argv[1], "%f", &loan_amount);
sscanf(argv[2], "%f", &yearly_rate);
sscanf(argv[3], "%d", &term_years);

monthly_rate = yearly_rate / 1200.;
term_months = term_years * 12;

x = 1.0;
for (i = 1; i <= term_months; ++i)
    x = x * (1.0 + monthly_rate);
y = (loan_amount * monthly_rate * x) / (x - 1);
payment = ((long) (y * 100. + 0.5));

printf("Amount: $%.2f\nAPR:    %.3f%%\nTerm:   %d years", loan_amount, 
	yearly_rate, term_years);
printf("\n\n%d monthly payments of $%.2f \n", term_months, payment / 100.);

}