/* rexx */ principal = -1 do UNTIL principal >= 0 say "Input Loan Amount: " parse pull principal end if principal = 0 then do say "Principal is zero, exiting" exit end principalNoExtra = principal periodicRate = -1 Do UNTIL periodicRate > 0 Say "Enter Yearly Interest Rate:" parse pull periodicRate End periodicRate = (periodicRate / 100) / 12 numPayments = -1 Do UNTIL numPayments > 0 Say "Enter the Number of years:" parse pull numPayments End numPayments = numPayments * 12 extraPmt = -1 Do UNTIL extraPmt >= 0 Say "Enter the extra payment amount per term (0 if none):" parse pull extraPmt End outputType = 0 Do until outputType = 1 | outputType = 2 Say "Enter 1 for text or 2 for html" parse pull outputType End Say "Enter output filename (without extension):" parse pull filename if outputType = 1 then filename = filename || ".txt" else filename = filename || ".html" call LINEOUT filename, "" /* Open file for writing */ numerator = principal * periodicRate * ((1 + periodicRate) ** numPayments) denominator = ((1 + periodicRate) ** numPayments) - 1 paymentAmt = numerator / denominator if outputType = 2 then do call LINEOUT filename, "" call LINEOUT filename, "" call LINEOUT filename, "" call LINEOUT filename, "" call LINEOUT filename, "" call LINEOUT filename, "" end else do call LINEOUT filename, "--------- AMORTIZATION SCHEDULE ---------" call LINEOUT filename, "Initial Principal: $" principal call LINEOUT filename, "Payment Amount: $" paymentAmt call LINEOUT filename, "" call LINEOUT filename, "Period | Beginning Principal | Payment Amount | Extra Payment | Total Interest | New Principal" end principal2 = principal totalPaid2 = 0 j = 0 numpay = 1 interestPaid2 = 0 do while principal2 > 0 j = j + 1 beginningPrincipal = principal2 IntPmt2 = principal2 * periodicRate principalPmt2 = (paymentAmt - IntPmt2) + extraPmt if principal2 < principalPmt2 then do principalPmt2 = principal2 numpay = j IntPmt2 = principal2 * periodicRate end principal2 = principal2 - principalPmt2 totalPaid2 = totalPaid2 + principalPmt2 + IntPmt2 interestPaid2 = interestPaid2 + IntPmt2 if outputType = 2 then do call LINEOUT filename, "" end else do call LINEOUT filename, j " | $" beginningPrincipal " | $" paymentAmt " | $" extraPmt " | $" interestPaid2 " | $" principal2 end end interestNoExtra = 0 principalTerm = 0 g = 0 do while principalNoExtra > 0 g = g + 1 interest_term = principalNoExtra * periodicRate principalTerm = paymentAmt - interest_term if principalNoExtra < principalTerm then principalTerm = principalNoExtra principalNoExtra = principalNoExtra - principalTerm interestNoExtra = interestNoExtra + interest_term end totalExtraPaid = extraPmt * numpay ROI = 0 if totalExtraPaid > 0 then do ROI = (interestNoExtra - interestPaid2) / totalExtraPaid end if extraPmt = 0 then do ROI = 0 end if outputType = 2 then do call LINEOUT filename, "
PeriodBeginning PrincipalPayment AmountExtra PaymentTotal InterestNew Principal
"j"$"beginningPrincipal"$"paymentAmt"$"extraPmt"$"interestPaid2"$"principal2"

" call LINEOUT filename, "Total Paid Accelerated ($" extraPmt " per payment): $" totalPaid2 "
" call LINEOUT filename, "Average ROI:" ROI * 100 "%
" end else do call LINEOUT filename, "" call LINEOUT filename, "Total Paid Accelerated ($" extraPmt " per payment): $" totalPaid2 call LINEOUT filename, "Average ROI per payment (interest avoided): " ROI * 100 "%" end call LINEOUT filename /* Close file */ say "Output written to:" filename