home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
d_b_a
/
86_11
/
la_int.prg
< prev
next >
Wrap
Text File
|
1986-10-06
|
4KB
|
138 lines
* -- PROGRAM NAME: .......... LA_INT.PRG
* -- PROGRAM TITLE: ......... Loan amortization: Interest Rate
* -- AUTHOR: ................ Venkat Penugonde
* Irvine Micro Arts, Irvine, CA
*
* -- SYSTEM ................. dBASE III or III +
* -- DATE FIRST CREATED .............. 08/20/86
* -- DATE MOST RECENTLY MODIFIED .....
*
* This program calculates the interest on a loan amortized over
* a given period where payments are made periodically at the end of
* a period
*
* Inputs required ......... 1) Principal Amount.
* 2) Periodic Payment Amount.
* 3) Total Number of Payment Periods.
* 4) Number of Payment Periods per Year.
*
* Outputs Generated ....... 1) Interest Rate per Period in % .
* 2) Annual Interest Rate in % .
*
PUBLIC principal, payment, t_period, istep, iaccuracy
pok = 'N'
DO WHILE .t.
CLEAR
principal = 0.00
payment = 0.00
t_period = 0
y_period = 0
@ 2, 27 SAY '* -- LOAN AMORTIZATION -- *'
@ 3, 27 SAY 'Computation of Interest Rate'
@ 6, 11 SAY 'Enter Principal [0 to exit] ................ $'
@ 6, 58 GET principal PICTURE '99,999,999.99'
READ
IF principal <= 0
EXIT
ENDIF
@ 7, 11 SAY 'Enter Periodic Payment ..................... $'
@ 7, 58 GET payment PICTURE '99,999,999.99'
@ 8, 11 SAY 'Enter Total Number of Payment Periods ....... '
@ 8, 65 GET t_period PICTURE '999'
@ 9, 11 SAY 'Enter Number of Payment Periods/Year ........ '
@ 9, 66 GET y_period PICTURE '99'
READ
IF payment <= 0 .OR. t_period <= 0 .OR. y_period <= 0
LOOP
ENDIF
ratio = principal/payment
int_prd = payment/principal
istep = 0.0001
iaccuracy = 0.00005
int_prds = int_prd
DO WHILE .t.
F = 0
FD = 0
DO function WITH int_prd, F
DO fderiv WITH int_prd, FD
int_prd = int_prd - (F/FD)
diff = int_prds - int_prd
IF diff < 0
diff = - diff
ENDIF
IF diff <= iaccuracy
* -- This above five lines could be replaced in dBASE III +
* -- with the following line
* IF ABS(int_prds - int_prd) <= iaccuracy
EXIT
ENDIF
int_prds = int_prd
ENDDO WHILE .t.
int_rate = int_prd * 100
ann_rate = int_rate * y_period
pok = 'Y'
@ 12, 11 SAY 'Output to Printer? [Y/N] ' GET pok PICTURE '!'
READ
IF pok = 'Y'
WAIT 'Please turn printer on & hit any key to continue' TO ok
SET PRINT ON
ENDIF
CLEAR
?
? SPACE(27) + '* -- LOAN AMORTIZATION -- *'
? SPACE(27) + 'Computation of Interest Rate'
?
? SPACE(19) + 'PRINCIPAL = ' + STR(principal,13,2)
? SPACE(19) + 'PERIODIC PAYMENT = ' + STR(payment,13,2)
? SPACE(19) + 'NUMBER OF PERIODS = ' ;
+ SPACE(7)+STR(t_period,3)
? SPACE(19) + 'NUMBER OF PERIODS/YEAR = ' ;
+ SPACE(8)+STR(y_period,2)
?
? SPACE(19) + 'INTEREST RATE/PERIOD [%] = ' ;
+ SPACE(8)+STR(int_rate,6,3)
? SPACE(19) + 'ANNUAL INTEREST RATE [%] = ' ;
+ SPACE(8)+STR(ann_rate,6,3)
?
ready = ' '
WAIT 'Press space Bar to Continue .......... ' TO ready
IF pok = 'Y'
SET PRINT OFF
ENDIF
ENDDO WHILE .t.
IF pok = 'Y'
SET PRINT OFF
ENDIF
RETURN
* --- Procedure To Calculate Function
PROCEDURE function
PARAMETER int, func
func = (1 - (1+int)**(-t_period))/int - ratio
RETURN
* -- EOP function
* --- Procedure to Calculate Derivative of Function
PROCEDURE fderiv
PARAMETER int, fdr
F1 = 0
DO function WITH int-istep, F1
F2 = 0
DO function WITH int+istep, F2
fdr = (F2 - F1)/(2*istep)
RETURN
* -- EOP fderiv
* --- EOF LA_INT.PRG