[alt.sources] mortgage program

bonl1@CFSMO.HONEYWELL.COM (Boniface Lee #1) (01/03/91)

Does anyone has a source program for mortgage payment calculations?  I like
to run it on my IBM PC...please e-mail the program...thanks!


Boniface Lee (bonl1@cfsmo.honeywell.com)
Honeywell Commercial Flight Systems - Minneapolis Operations
(612) 785-4629

joeb@marque.mu.edu (01/04/91)

Here's a simple little mortgage calcuator program.  It prints tables of monthly
payments for different principals and different interest rates; tables are
printed for 15-year and 30-year mortgages.  You can optionally include a
specific principal amount in the table by including it on the command line.
If desired, it should be easy to include a specific interest rate also.
Have fun!

------------------------------------------------------------------------

/*
**  Compute monthly mortgage payments for 15 and 30 year mortgages, at
**  various interest rates.  Expects tab stops every 8 characters.
**
**  Usage:  mortgage [amount]
*/

#define  P_LOW		 50000		/* range of principal */
#define  P_HIGH		200000
#define  P_INCR		 25000

#define  Y_LOW		15		/* range of mortgage terms */
#define  Y_HIGH		30
#define  Y_INCR		15

#define  R_LOW		.085		/* range of interest rates */
#define  R_HIGH		.125
#define  R_INCR		.005

double pow(double,double);

main(argc,argv)
    int argc;
    char *argv[];
{
	int principal, years, amount = 0;
	float rate;
	char did_it;

	if (argc > 1) {
	    if (argv[1][0] == '?') {
		usage();
		exit(1);
	    }
	    amount = atoi(argv[1]);
	}

	for (years=Y_LOW; years<=Y_HIGH; years+=Y_INCR) {
	    printf("\n\t\tMonthly Payment, %d-year mortgage\n",years);
	    printf("Principle\t\tInterest Rate\n");
	    for (rate=R_LOW; rate<R_HIGH+R_INCR/2.; rate+=R_INCR)
		printf("\t  %4.1f%%",rate*100.);
	    printf("\n");
	    for (rate=R_LOW; rate<R_HIGH+R_INCR/2.; rate+=R_INCR)
		printf("\t  -----");
	    printf("\n");

	    did_it = 0;
	    for (principal=P_LOW; principal<=P_HIGH+P_INCR; principal+=P_INCR) {
		if ( amount && (!did_it) &&
		  ((amount < principal) || (principal > P_HIGH)) ) {
		    one_line(amount,years);
		    did_it++;
		}
		if (principal <= P_HIGH)
		    one_line(principal,years);
	    }
	}
}

usage()
{
	printf("Mortgage payment calculator\n\n");
	printf("Usage: mortgage [amount]\n");
}

one_line(amount,years)
    int amount;
    int years;
{
	float rate;

	printf("$%6d",amount);
	for (rate=R_LOW; rate<R_HIGH+R_INCR/2.; rate+=R_INCR)
	    printf("\t%7.2f", (float)
	      (amount * rate/12 / (1 - 1 /
	      (double)pow((double)(1.+rate),(double)years) )) );
	printf("\n");
}

----------------------------------------------

kevin@ttidca.TTI.COM (Kevin Carothers) (01/04/91)

In article <9101022144.AA13145@hp370b.CFSMO.Honeywell.COM> bonl1@CFSMO.HONEYWELL.COM (Boniface Lee #1) writes:
>
>Does anyone has a source program for mortgage payment calculations?  I like
>to run it on my IBM PC...please e-mail the program...thanks!
>
>
>Boniface Lee (bonl1@cfsmo.honeywell.com)
>Honeywell Commercial Flight Systems - Minneapolis Operations
--

Sure.
*I* work at CITIBANK :-)  (But seriously, folks...)

just compile and run, and keep hitting cariage returns to get 
monthly payment, interest, principal and balance info, and stop 
bugging your loan officer.

I developed this on a PDP-11/70 (!!), and run it (with a couple of 
silly lint errors) on my SPARC. Hope it helps.

--

 
/*
 Program to print a mortgage payment
 debt over a period of years
 */

#include <stdio.h>

main()
{
	int c,i;
	float mort_amt;
	float mort_int;
	float mort_pmt;
	float intrst;
	int  mort_yrs;
	float t_int;
	float t_t;
	float t_tmp;
	float temp;
	float tmp_amt;
	float tmp_int;
	int tmp_yrs;
	int  y_yrs;
	float y_int;
	float y_t;
	float y_tmp;
	
	printf("Enter the loan amount: ");
	scanf("%f",&mort_amt);

	printf("Enter the years of the loan: ");
	scanf("%d",&mort_yrs);
	tmp_yrs=mort_yrs;

	printf("Enter the interest rate: ");
	scanf("%f",&mort_int);

	if(mort_int < 1.) mort_int *= 100.;
	intrst = (mort_int/100.)/12.;
	mort_yrs *= 12;
	temp = 1.;

	do {
		temp *= (1. +intrst);
		mort_pmt += (1./temp);
		mort_yrs--;
	} while(mort_yrs > 0);

	temp = mort_amt/mort_pmt;
	mort_int /= 100.;
	y_tmp = y_int = y_t = 0.;
	mort_yrs = 0;
	tmp_amt = mort_amt;

		printf("\nloan amount: $%6.2f\t\t",tmp_amt);
		printf("loan rate: %4.2f%\n",mort_int*100.);
		printf("monthly payment: $%10.2f\n\n",temp);

		if((c=getchar()) != EOF)
		    if((c=getchar()) == EOF)
			exit();
			
	do {
	
		printf("year: %d",++mort_yrs);
		printf("\nloan amount: $%6.2f\t\t",tmp_amt);
		printf("loan rate: %4.2f%\n",mort_int*100.);
		printf("monthly payment: $%10.2f\n\n",temp);

		printf("month\tpayment\t\tinterest\tprincipal\tbalance\n");
		printf("-----\t-------\t\t--------\t---------\t-------\n");

		t_tmp = t_int = t_t = 0.;
		for(i=1 ; i <= 12 ; ++i) {

			if(mort_amt <= .01) {
				mort_yrs = tmp_yrs;	/* force exit   */;
				break;
			}
			tmp_int = temp - (mort_amt*(mort_int/12.));
			mort_amt -= tmp_int;

			printf("%2d\t$%7.2f\t$%7.2f\t$%7.2f\t$%7.2f\n",
				i,temp,temp-tmp_int,tmp_int,mort_amt);

			t_tmp += temp;
			t_t += tmp_int;
			t_int +=temp-tmp_int;
	
			y_tmp+= temp;
			y_t += tmp_int;
			y_int += temp-tmp_int;

		}

		printf("     \t_______\t\t________\t_________\n");
	    	printf("     \t$%7.2f\t$%7.2f\t$%7.2f\n",t_tmp,t_int,t_t);

		printf("     \t_______\t\t________\t_________\n");
	    	printf("     \t$%7.2f\t$%7.2f\t$%7.2f\n",
		  y_tmp,y_int,y_t);

		printf("     \t=======\t\t========\t=========\n");

		if((c=getchar()) == EOF)
			break;
				
	} while(mort_yrs< tmp_yrs);
}

davidsen@sixhub.UUCP (Wm E. Davidsen Jr) (01/06/91)

Here's a program I pulled from somewhere once upon a time... I make no
claims in favor of it, and shoud you have have any problem please tell
the authors, not me.

/*
 *
 * loan.c
 * @(#) loan.c amoritization program
 * 
 * acronym:    loan amortization program
 *             ----
 *
 * purpose:	calculates monthly payment, future value
 *		and creates an amortization schedule
 *
 * 06/27/84	Bill Gregg, Informatics General Corp.
 * 07/12/84     Revision 1
 * 07/12/84	Revision 2
 * 11/05/85	Jane Medefesser, Implementation NPSN Unix (wilbur)
 *		compile as follows: 'cc -o <outfile> loan.c -lm'
 * 12/05/85	Changes to direct output to a file.
 * 03/02/88	Implemented on Eternity 5.3.1
 *
 */

#include <stdio.h>
#include <math.h>

/*
 *
 */
 
main() 		/* loan program */
{
	float amt, term, rate, ic;
	float r, temp, pmt, fv;
	float exp, prin, x, y, mbeg, mnbr, yrint = 0;
	int month, i, k, a = 0, yr=1;
	char d, filename[9], c;
	FILE *fp;
	/*  prompt for input from terminal  */

	printf("Enter principal amount: ");
	scanf("%f", &amt);

	printf("Enter term in years: ");
	scanf("%f", &term);

	printf("Enter interest rate in percent: ");
	scanf("%f", &rate);

	printf("Enter month payments begin (ex: 8 = August): ");
	scanf("%f", &mbeg);

	/*  compute payment and future value  */

	r = rate/100.0;
	x = 1.0 + r/12.0;
	y = term*12.0;
	temp = (1.0 / pow(x,y));
	pmt = (amt*r/12.0) / (1-temp);
	k = term*12;
	fv = pmt*k;
	ic = fv - amt;

	printf("Do you want the report directed to a file or to the screen?");
	printf("\n[f = file / s = screen] : ");
	d = getchar();      /* This is only here to eat up the '\n' left over
			       from the last scanf. */
	d = getchar();
	switch(d) {
	     case 'f':
	     d = getchar();
	     printf("\nEnter a filename: ");
	     scanf("%s", filename);
	     while((c = getchar()) != '\n') {
	     filename[a] = c; a++; }
	     fp = fopen(filename, "w");
	     break;
	     default:
	     fp = stdout;
	     break;
	     }

	     /*  print header  */
  
	   fprintf(fp,"\n\t *** Amortization Schedule ***\n\n");
	   fprintf(fp,"Principal:  %.2f\n", amt);
	   fprintf(fp,"Future value:  %.2f\n", fv);
	   fprintf(fp,"Term of loan in years:  %.1f\n", term);
	   fprintf(fp,"Interest Rate:  %3.3f\n", rate);
	   fprintf(fp,"Total Interest Charge:  %.2f\n", ic);
	   fprintf(fp,"Payment:  %.2f\n", pmt);
	   fprintf(fp,"\nMONTH\tPRINCIPAL\tINTEREST\tBALANCE\n");
  
	   /* start of loop to print amortization schedule */
  
	   mnbr=mbeg;
	   for (i=1; i<=k; i++) {
	      month = i;
	      exp = amt*(r/12.0);
	      yrint=yrint+exp;
	      prin = pmt-exp;
	      amt = amt-prin;
	      mnbr++;
	      fprintf(fp,"%d\t %.2f\t\t %.2f\t\t %.2f\n", month, prin, exp, amt);
	      if (mnbr > 12 ) {
	      fprintf(fp,"\t\tInterest paid for year %d is %.2f\n\n",yr,yrint);
	      yr++;
	      yrint=0;
	      mnbr=1;
              }
}
	     fprintf(fp,"\t\tInterest paid for year %d is %.2f\n\n",yr,yrint);
	     fclose(fp);
}


-- 
bill davidsen - davidsen@sixhub.uucp (uunet!crdgw1!sixhub!davidsen)
    sysop *IX BBS and Public Access UNIX
    moderator of comp.binaries.ibm.pc and 80386 mailing list
"Stupidity, like virtue, is its own reward" -me