One of the nice things about Fortran is that most compilers will compile just about any legacy Fortran code. Take for example the following program which computes the amount of a debt with interest compounded, the amount of annual instalment repayments, and a repayment schedule. This is a commercial loan which allows a sum to be borrowed without repayment of principal or interest for a fixed period of time. Repayment then occurs in instalments over several more years.

C DEBT REPAYMENT SCHEDULE INTEGER YEAR, BDATE REAL I, INT, INTAMT 10 READ(5,1,END=50) AMT,I,N,K,BDATE 1 FORMAT(F7.0,F2.2,2I3,I4) WRITE(6,2) BDATE,AMT,I,N 2 FORMAT('1',18X,'REPAYMENT SCHEDULE'/5X,' LOAN DATE ', 1'DEC. 31, ',I4,5X,'AMOUNT BORROWED ',F8.0,' INTEREST RATE ', 2F4.2/5X,'REPAYMENT TO BEGIN AFTER ',I3,' YEARS'// 414X,'REPAYMENT',16X,'PRINCIPAL'/5X,'YEAR',7X,'AMOUNT',4X, 5'INTEREST',5X,'REDUCTION BALANCE') CMPAMT=AMT*(1.+I)**N WRITE(6,3) CMPAMT 3 FORMAT(53X,F8.0) PMTAMT=CMPAMT/(((1.+I)**K-1.)/(I*(1.+I)**K)) DO 15 J=1,K YEAR=BDATE+N+J INT=CMPAMT*I BALRD=PMTAMT-INT CMPAMT=CMPAMT-BALRD 15 WRITE(6,4) YEAR,PMTAMT,INT,BALRD,CMPAMT 4 FORMAT(5X,I4,6X,F8.0,3X,F8.0,5X,F8.0,6X,F8.0) INTAMT=PMTAMT*FLOAT(K)-AMT WRITE(6,5) INTAMT 5 FORMAT(/5X,'TOTAL INTEREST CHARGE ',F8.0) GOTO 10 50 STOP END

Here is the input to the program:

0100000100050041978

This uses the following formula to calculate the future amount, A:

A = P(1+r)^n

where **P** is the amount originally borrowed, **r** is the interest rate, and **n** the number of periods before repayment begins. For the example given, the balance before repayment is therefore 100000*(1+0.1)^5 = $161,051.

This amount must be repaid in installments over the agreed-upon period. As payments are made, the unpaid amount continues to accrue interest, therefore computation of the amount which will repay principal and all interest in even installments is calculated using the formula:

where **A** is the amount to be repaid, **r** is the interest rate, and **n** the number of installment payments. This makes the assumption that the installment payments will be made at the end of each repayment year.

And the corresponding output:

The re-engineering of code like this (albeit small) is not that difficult, due to the lack of unstructured jumps in the code.