home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / dba1186.zip / LA_INT.PRG < prev    next >
Text File  |  1986-10-06  |  4KB  |  138 lines

  1. * -- PROGRAM NAME: .......... LA_INT.PRG
  2. * -- PROGRAM TITLE: ......... Loan amortization: Interest Rate
  3. * -- AUTHOR: ................ Venkat Penugonde
  4. *                             Irvine Micro Arts, Irvine, CA
  5. *
  6. * -- SYSTEM ................. dBASE III or III +
  7.  
  8. * -- DATE FIRST CREATED .............. 08/20/86
  9. * -- DATE MOST RECENTLY MODIFIED .....
  10. *
  11. *  This program calculates the interest on a loan amortized over
  12. *  a given period where payments are made periodically at the end of
  13. *  a period
  14. *
  15. *  Inputs required .........  1) Principal Amount.
  16. *                             2) Periodic Payment Amount.
  17. *                             3) Total Number of Payment Periods.
  18. *                             4) Number of Payment Periods per Year.
  19. *
  20. * Outputs Generated .......   1) Interest Rate per Period in % .
  21. *                             2) Annual Interest Rate in % .
  22. *
  23.  
  24.  
  25. PUBLIC  principal, payment, t_period, istep, iaccuracy
  26. pok = 'N'
  27. DO WHILE .t.
  28.   CLEAR
  29.   principal = 0.00
  30.   payment   = 0.00
  31.   t_period  = 0
  32.   y_period  = 0
  33.  
  34.   @   2, 27   SAY  '* -- LOAN AMORTIZATION  -- *'
  35.   @   3, 27   SAY  'Computation of Interest Rate'
  36.   @   6, 11   SAY  'Enter Principal [0 to exit] ................ $'
  37.   @   6, 58   GET  principal PICTURE '99,999,999.99'
  38.   READ
  39.   IF principal <= 0
  40.     EXIT
  41.   ENDIF
  42.   @   7, 11   SAY  'Enter Periodic Payment ..................... $'
  43.   @   7, 58   GET  payment    PICTURE '99,999,999.99'
  44.   @   8, 11   SAY  'Enter Total Number of Payment Periods ....... '
  45.   @   8, 65   GET  t_period   PICTURE '999'
  46.   @   9, 11   SAY  'Enter Number of Payment Periods/Year ........ '
  47.   @   9, 66   GET  y_period   PICTURE '99'
  48.   READ
  49.  
  50.   IF payment <= 0 .OR. t_period <= 0 .OR. y_period <= 0
  51.     LOOP
  52.   ENDIF
  53.   ratio      =  principal/payment
  54.   int_prd    =  payment/principal
  55.   istep      =  0.0001
  56.   iaccuracy  =  0.00005
  57.   int_prds   =  int_prd
  58.  
  59.   DO WHILE  .t.
  60.     F   =  0
  61.     FD  =  0
  62.     DO function  WITH  int_prd, F
  63.     DO fderiv    WITH  int_prd, FD
  64.     int_prd  =  int_prd  -  (F/FD)
  65.     diff     =  int_prds - int_prd
  66.     IF diff < 0
  67.       diff  = - diff
  68.     ENDIF
  69.     IF diff <=  iaccuracy
  70.     * -- This above five lines could be replaced in  dBASE III +
  71.     * -- with the following line
  72.     *    IF ABS(int_prds - int_prd) <=  iaccuracy
  73.        EXIT
  74.     ENDIF
  75.     int_prds  =  int_prd
  76.   ENDDO WHILE  .t.
  77.  
  78.  
  79.   int_rate = int_prd * 100
  80.   ann_rate = int_rate * y_period
  81.   pok = 'Y'
  82.   @   12, 11   SAY  'Output to Printer? [Y/N] ' GET pok  PICTURE '!'
  83.   READ
  84.   IF pok = 'Y'
  85.     WAIT  'Please turn printer on & hit any key to continue' TO  ok
  86.     SET PRINT ON
  87.   ENDIF
  88.   CLEAR
  89.   ?
  90.   ? SPACE(27) + '* -- LOAN AMORTIZATION -- *'
  91.   ? SPACE(27) + 'Computation of Interest Rate'
  92.   ?
  93.   ? SPACE(19) + 'PRINCIPAL                 =  ' + STR(principal,13,2)
  94.   ? SPACE(19) + 'PERIODIC PAYMENT          =  ' + STR(payment,13,2)
  95.   ? SPACE(19) + 'NUMBER OF PERIODS         =  ' ;
  96.     + SPACE(7)+STR(t_period,3)
  97.   ? SPACE(19) + 'NUMBER OF PERIODS/YEAR    =  ' ;
  98.     + SPACE(8)+STR(y_period,2)
  99.   ?
  100.   ? SPACE(19) + 'INTEREST RATE/PERIOD [%]  =  ' ;
  101.     + SPACE(8)+STR(int_rate,6,3)
  102.   ? SPACE(19) + 'ANNUAL INTEREST RATE [%]  =  ' ;
  103.   + SPACE(8)+STR(ann_rate,6,3)
  104.  
  105.   ?
  106.   ready = ' '
  107.   WAIT 'Press space Bar to Continue .......... ' TO ready
  108.   IF pok = 'Y'
  109.     SET PRINT OFF
  110.   ENDIF
  111. ENDDO WHILE .t.
  112. IF pok = 'Y'
  113.  SET PRINT OFF
  114. ENDIF
  115. RETURN
  116.  
  117. * --- Procedure To Calculate Function
  118. PROCEDURE  function
  119. PARAMETER  int, func
  120. func  =   (1 - (1+int)**(-t_period))/int - ratio
  121. RETURN
  122. * -- EOP function
  123.  
  124. * --- Procedure to Calculate Derivative of Function
  125. PROCEDURE fderiv
  126. PARAMETER  int, fdr
  127. F1 = 0
  128. DO function WITH  int-istep, F1
  129. F2 = 0
  130. DO function WITH  int+istep, F2
  131. fdr  =  (F2 - F1)/(2*istep)
  132. RETURN
  133. * -- EOP fderiv
  134.  
  135. * --- EOF  LA_INT.PRG
  136.  
  137.  
  138.