home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol115 / mortgage.pqi / MORTGAGE.PLI
Encoding:
Text File  |  1985-02-10  |  9.3 KB  |  283 lines

  1. mortgage: proc options (main);
  2.     put edit (' ', ' ', ' ',
  3.     '*****************************************************',
  4.     '*          Mortgage Amortization Program            *',
  5.     '*          =============================            *',
  6.     '*                      -- by John W. Bishop,        *',
  7.     '*                         February 7, 1983.         *',
  8.     '*                                                   *',
  9.     '*  This program will compute monthly payment, total *',
  10.     '*  interest, etc., for any principal and rate, with *',
  11.     '*  standard Canadian rules (semi-annual compounding *',
  12.     '*  of interest,  blended payments of  principal and *',
  13.     '*  interest, no final "balloon payment", etc.  User *',
  14.     '*  can also obtain a  printout of the  amortization *',
  15.     '*  table for either the full amortization period or *',
  16.     '*  the term of the mortgage. Any licensed CP/M user *',
  17.     '*  may make use of this program (for non-commercial *',
  18.     '*  purposes) if (s)he so desires.                   *',
  19.     '*  Note: Portions of this program,  (c) 1982, 1980, *',
  20.     '*  DIGITAL RESEARCH INC.  (This program was written *',
  21.     '*  in PL/I-80, on an H-89 computer.)                *',
  22.     '*****************************************************',
  23.  
  24.     '               Press any key to begin')
  25.         (skip, a);
  26.     call keyin1;
  27.     dcl page_number fixed dec (3) static init (1);
  28.     dcl form_feed    char (1) static init ('^L');
  29.     dcl rdstat entry returns (bit (1)),
  30.         coninp entry returns (char (1));
  31.     dcl clear char (2) static init ('^[E');
  32.     dcl answer char (1);
  33.     dcl (syslist, sysprint) file;
  34.     dcl (more, print_it, yes, no, hard_copy) bit (1);
  35.         yes = '1'b; no = '0'b; more = '1'b; print_it = '0'b;
  36.     dcl (annual_rate, semi_annual_rate, monthly_rate,
  37.         amort_months, term_months, amortization_factor) float;
  38.     dcl (term_dec, amort_dec) fixed dec (5);
  39.     dcl (principal, monthly_payment, monthly_interest, total_paid,
  40.         principal_repaid, total_interest, start_principal,
  41.         end_principal) fixed dec (9,2);
  42.     dcl     catch_convert     fixed dec (15, 11),
  43.         amort_factor_dec fixed dec (9,6),
  44.         monthly_rate_dec fixed dec (9,9);
  45.     dcl ftc entry (float binary) returns (char (17) var);
  46.     open file (sysprint) stream output linesize (0) title ('$con');
  47.     put file (sysprint) edit (clear) (a);
  48.     put file (sysprint) edit
  49.         ('Do you want information printed, ' || 
  50.             'as well as listed on the screen?')
  51.                 (skip, a);
  52.     call keyin1;
  53.     if index ('NnYy', answer) > 2 
  54.         then print_it = '1'b;
  55.         else print_it = '0'b;
  56.     put edit ('Turn on printer, then press any key.')
  57.                 (skip(2), a);
  58.     call keyin1;
  59.     open file (syslist) stream output
  60.                 title ('$lst') linesize (0);
  61. do while (more);
  62.     put file (sysprint) edit (clear)(a);
  63.     put file (sysprint) edit 
  64.         ('Mortgage Amortization Information',
  65.          '=================================')
  66.         (skip, col (25), a);
  67.     put file (sysprint) edit ('Amount to be amortized? ')
  68.             (skip(2), col (10), a);
  69.     get list (principal);
  70.     end_principal = principal;
  71.     put file (sysprint) edit ('Nominal annual interest rate (%)? ')
  72.             (skip, col (10), a);
  73.     get list (annual_rate);
  74.     put file (sysprint) edit ('Amortized over how many months? ')
  75.             ( col (10), a);
  76.     get list (amort_months);
  77.     amort_dec = amort_months;
  78.     put file (sysprint) edit ('Mortgage term (in months)? ')
  79.             ( col (10), a);
  80.     get list (term_months);
  81.     term_dec = term_months;
  82.     semi_annual_rate = annual_rate / 200.0;
  83.     monthly_rate = (1.0 + semi_annual_rate) ** (1.0E0/6.0E0) - 1.0;
  84.     amortization_factor =
  85.         (1.0 - 1.0 / (1.0 + monthly_rate) ** amort_months)
  86.             / monthly_rate;
  87.  
  88.     catch_convert    = dec (ftc (amortization_factor), 15, 11);
  89.     amort_factor_dec = catch_convert;
  90.  
  91.     catch_convert    = dec (ftc (monthly_rate), 15, 11);
  92.     monthly_rate_dec = catch_convert;
  93.  
  94.     monthly_payment = 0.005 + principal / amort_factor_dec;
  95.     total_paid = monthly_payment * amort_dec;
  96.     total_interest = total_paid - principal;
  97.  
  98.     put file (sysprint) edit 
  99.         ('Monthly payment (principal + interest) is ',
  100.                 monthly_payment)
  101.             (skip(2), col (10), a, p'$$$,$$9v.99');
  102.  
  103.     put file (sysprint) edit
  104.         ('Over full amortization period of ',amort_dec,' months,',
  105.             ' total repayment would be ', total_paid,
  106.             ' of which ', total_interest, ' would be interest.')
  107.         (skip,col (10), a, p'z,zz9', a,
  108.             skip, col (20), a, p'$$,$$$,$$9v.99',
  109.             skip, col (20), a, p'$$,$$$,$$9v.99', a);
  110.  
  111.     if print_it
  112.         then do;
  113.             put file (syslist) skip (2);
  114.             call show_stuff (syslist);
  115.         end;
  116.  
  117.     put file (sysprint) edit
  118.         ('Do you want to see the amortization table?')
  119.         (skip, col (15), a);
  120.     call keyin1;
  121.     if index ('Yy', answer) > 0
  122.         then do;
  123.             put file (sysprint) edit 
  124.                 ('on Screen, or Printer [ S or P ] ?')
  125.                 (skip, col (30), a);
  126.             call keyin1;
  127.             if index ('Pp', answer) > 0
  128.                 then hard_copy = yes;
  129.                 else hard_copy = no;
  130.             if hard_copy
  131.                 then call print_the_table (syslist);
  132.                 else call print_the_table (sysprint);
  133.         end;
  134.  
  135.     put file (sysprint) edit 
  136.         ('Do you wish to continue calculations? ')
  137.         (skip (2), col (20), a);
  138.     call keyin1;
  139.     if index ('Yy',answer) > 0 
  140.         then more = yes;
  141.         else more = no;
  142. end /* big do while loop */;
  143.  
  144. return;
  145.  
  146. keyin1: proc;
  147.     do while (~ rdstat ()); end;
  148.     answer = coninp ();
  149.     return;
  150. end keyin1;
  151.  
  152. show_stuff: proc (output);
  153.     dcl output file variable;
  154.  
  155.     put file (output) edit ('Mortgage particulars',
  156.                 '====================')
  157.             (skip, col(30), a);
  158.     put file (output) edit ('Principal to be amortized: ',
  159.         principal) (skip, col (10), a, p'$$,$$$,$$9v.99');
  160.     put file (output) edit ('Nominal annual interest rate: ',
  161.         annual_rate,' %')(skip, col (10), a, p'zz9v.999',a);
  162.     put file (output) edit ('Amortization term (months): ',
  163.         amort_dec) (skip, col (10), a, p'zz,zz9');
  164.     put file (output) edit ('Monthly payment, P & I: ',
  165.         monthly_payment) (skip, col (10), a, p'$$$,$$9v.99');
  166.  
  167.     put file (output) edit
  168.         ('Over full amortization period of ',amort_dec,' months,',
  169.             ' total repayment would be ', total_paid,
  170.             ' of which ', total_interest, ' would be interest.')
  171.         (skip (2), col (10), a, p'z,zz9', a, 
  172.             skip, col (20), a, p'$$,$$$,$$9v.99',
  173.             skip, col (20), a, p'$$,$$$,$$9v.99', a);
  174.     put file (output) skip;
  175.     return;
  176. end show_stuff;
  177.  
  178. print_the_table: proc (output);
  179.     dcl output file;
  180.     dcl (year_count, month_count, max_months, total_months,
  181.         check, years_on_page, max_years_on_page) fixed bin (15);
  182.     if hard_copy 
  183.         then max_years_on_page = 3;
  184.         else max_years_on_page = 1;
  185.     year_count = 1; month_count = 0; page_number = 1;
  186.     total_months = 0; years_on_page = 0;
  187.     put edit ('Listing for the full Amortization',
  188.         ' (' , amort_dec , ' months),',
  189.         'or for the mortgage Term (', term_dec,
  190.         ' months) ? [ A  or T ] :')
  191.         (skip(2), col (15), a, a, p'zzzz9', a,
  192.          skip(1), col (15), a, p'zzzz9', a);
  193.     check = 0;
  194.  
  195.     do while (check = 0);
  196.         call keyin1;
  197.         check = index ('TtAa',answer);
  198.         end;
  199.  
  200.     if check < 3
  201.         then max_months = term_dec;
  202.         else max_months = amort_dec;
  203.     call new_page_rtn;
  204.  
  205.     do while (total_months < max_months & end_principal > 0);
  206.         start_principal = end_principal;
  207.         monthly_interest = start_principal*monthly_rate_dec+0.005;
  208.         principal_repaid = monthly_payment - monthly_interest;
  209.         end_principal = start_principal - principal_repaid;
  210.         total_months = total_months + 1;
  211.         month_count = month_count + 1;
  212.         put file (output) edit 
  213.             ('|', month_count, ' |', start_principal,
  214.             '|', monthly_interest, '|', principal_repaid,
  215.             '|', monthly_payment, '|', end_principal,
  216.             '|', total_months, ' |')
  217.             (skip, a, p'zz9', a, p'$$$$,$$9v.99-',
  218.             a, p'zzz,zz9v.99-', a, p'zzz,zz9v.99-',
  219.             a, p'zzz,zz9v.99-', a, p'$$$$,$$9v.99-',
  220.             a, p'zzz9', a);
  221.  
  222.         if (month_count = 12 & total_months < max_months) then
  223.             do;
  224.                 month_count = 0;
  225.                 year_count = year_count + 1;
  226.                 years_on_page = years_on_page + 1;
  227.                 if years_on_page > max_years_on_page
  228.                   then call new_page_rtn;
  229.                   else put file (output) edit 
  230.                     ('Year Number ',year_count,
  231.                      '===============')
  232.                     (skip(2), col (30), a, p'zz9',
  233.                      skip, col (30), a);
  234.             end;
  235.  
  236.         end;
  237.     put file (output) edit ('End of listing.')
  238.                 (skip (2), col (40), a);
  239.     return;
  240.  
  241. new_page_rtn: proc;
  242.  
  243.     if hard_copy 
  244.         then put file (output) edit (form_feed)(a);
  245.         else do;
  246.             put file (output) edit
  247.                 ('Press any key to continue')
  248.                 (skip, col (25), a);
  249.             call keyin1;
  250.             put file (output) edit (clear) (a);
  251.             end;
  252.     put file (output) edit ('Mortgage Amortization Table',
  253.         'Page #', page_number,'Year #', year_count)
  254.         (skip, col (20), a, col (55), a, p'zz9',
  255.          skip, col (25), a, p'zz9');
  256.  
  257.     put file (output) edit ('Principal', principal, 'Annual rate',
  258.         annual_rate, '%', 'Amortized over', amort_dec,
  259.         ' months','Mortgage term', term_dec, ' months.')
  260.         (skip (2), col (15), a, col (30), p'$$$$$,$$9v.99',
  261.          skip (1), col (15), a, col (30), p'zz9v.999b', a,
  262.          skip (1), col (15), a, col (30), p'zzz9', a,
  263.          skip (1), col (15), a, col (30), p'zzz9', a);
  264.  
  265.     put file (output) edit 
  266.         ('Month| Before Pmt |  Interest | Principal |'||
  267.         'Monthly pmt| After Paymt|Pmt #|',
  268.          '=====|============|===========|===========|'||
  269.         '===========|============|=====|')
  270.         (skip, a, skip, a);
  271.     
  272.     page_number = page_number + 1;
  273.     years_on_page = 1;
  274.     month_count = 0;
  275.     
  276.     return;
  277.  
  278. end new_page_rtn;
  279.  
  280. end print_the_table;
  281.  
  282. end mortgage;
  283.