Project Description

This projects calculates a loan amortization using several inputs. It calculates the effective ROI if additional payments are made.
The program can output the schedule in either Txt or html.

Source Code:

  /* rexx */
Do Forever
Do until datatype(loan, "n") & loan > 0
Say "Please enter the loan amount:"
Parse Pull loan
If datatype(loan, "n") & loan <= 0 Then
Say "Sorry! Loan amount must be a positive number (doesn't include 0). Try again"
End
Do until datatype(air, "n") & air >= 0
Say "Now enter the annual interest rate (can be 0):"
Parse Pull air
If datatype(air, "n") & air < 0 Then
Say "Sorry! The annual interest rate must be a number greater or equal to 0. Try again"End
Do until datatype(term, "n") & term > 0
Say "Now enter the loan term in years:"
Parse Pull term
If datatype(term, "n") & term <= 0 Then
Say "Sorry! The loan term years must be a positive number. Try again"
End
Do until datatype(app, "n") & app >= 0
Say "Finally enter the additional principal payment per month (if none input 0):"
Parse Pull app
If datatype(app, "n") & app < 0 Then
Say "Sorry! The loan additional principal payments must be a positive amount or 0. Try again"
End
Do until datatype(dataset, "alpha") & \datatype(dataset, "n")  & (dataset \=  " " & length(dataset) < 15)
Say "Enter a name for your datset, avoid symbols of any kind only letters"
Parse Pull dataset
If datatype(dataset, "n") Then do
Say "Sorry! the dataset name can't be numeric.Try again"
End
If length(dataset) >= 15 then do
Say " Sorry! Please keep the dataset name less than 15 characters. Try again"
End
End
Do until datatype(type, "alpha") & (type = "html" | type = "txt")
Say "Finally, enter the type for your datset (txt or html):"
Parse Pull type
End
Leave
End
dataset = dataset"."Time()"."Userid()
Say dataset
filename = dataset"."type
rate = air / 12 / 100
term = term * 12
If rate == 0 Then
monthly = loan / term
Else
monthly = loan * (( rate * (1 + rate) ** term) / (( 1+ rate) ** term - 1 ))
Tinterest = 0
Tapp = 0
OgLoan = loan
ogApp = app
period = 1
if type = "txt" then do
Say "txt"
Call lineout(filename), "| Period | Beginning principal | Payment Amount | Extra Payment Amount | Total Interest | New Principal |"
Call lineout(filename), "|:-------:|:-------------------:|:--------------:|:--------------------:|:--------------:|:-------------:|"
Do while loan > 0
interest = loan * rate
principal = monthly - interest
If loan < principal + app Then DO
principal = loan
app = 0
End
Nloan = loan - principal - app
Call lineout(filename), "|"right(period,5) "|" "|" right(loan,15) "|"  "|" right(monthly,13) "|" "|" right(app,20) "|" "|" right(Interest,15) "|" "|" right(Nloan,10) "|"
loan = Nloan
Tinterest = Tinterest + interest
Tapp = Tapp + app
period = period + 1
End
Call lineout(filename), " "
End
Else if type = "html" then do
Say "HTML"
Call lineout (filename), 
Call lineout (filename), 
Call lineout (filename), 
Call lineout (filename), 
Call lineout(filename), ""
Call lineout(filename), "<tr><th>Period</th><th>Beginning principal</th><th>Payment Amount</th><th>Extra Payment Amount</th><th>Total Interest</th><th>New Principal</th></tr>"
app = OgApp
loan = OgLoan
Tinterest = 0
Tapp = 0
period = 1
Do while loan > 0
interest = loan * rate
principal = monthly - interest
If loan < principal + app Then DO
principal = loan
app = 0
End
Nloan = loan - principal - app
Call lineout(filename), "<tr><td>"period"</td><td>"loan"</td><td>"monthly"</td><td>"app"</td><td>"Interest"</td><td>"Nloan"</td></tr>"
Call lineout(filename),
Call lineout(filename),
loan = Nloan
Tinterest = Tinterest + interest
Tapp = Tapp + app
period = period + 1
End
Say "here- final html"
Call lineout(filename), "
" Call lineout(filename), " " End Tinterest2 = 0 app = 0 loan = OgLoan Do while loan > 0 interest = loan * rate principal = monthly - interest If loan < principal + app Then DO principal = loan app = 0 End Nloan = loan - principal - app loan = Nloan Tinterest2 = Tinterest2 + interest period = period + 1 End IntSaved = Tinterest2 - Tinterest If Tapp == 0 then Eroi = 0 Else Eroi = (IntSaved / Tapp) * 100 Call lineout(filename), " " If Tapp > 0 then Do Call lineout(filename), "ROI Summary" Call lineout(filename),"Total Additional Payment Paid" Tapp Call lineout(filename), "Total Interest saved" IntSaved Call lineout(filename), "Effective ROI" Eroi||"%" say "here - final" End Call lineout(filename), " " Say "User" UserId() Say "Date" Date() "Time" Time() Say "finishing exiting programn " EXIT End

Example output HTML:

PeriodBeginning principalPayment AmountExtra Payment AmountTotal InterestNew Principal
110000.00117.303725.009870.70
29870.70117.303724.689741.08
39741.08117.303724.359611.13
49611.13117.303724.039480.86
59480.86117.303723.709350.26
69350.26117.303723.389219.34
79219.34117.303723.059088.09
89088.09117.303722.728956.51
98956.51117.303722.398824.60
108824.60117.303722.068692.36
118692.36117.303721.738559.79
128559.79117.303721.408426.89
138426.89117.303721.078293.66
148293.66117.303720.738160.09
158160.09117.303720.408026.19
168026.19117.303720.077891.96
177891.96117.303719.737757.39
187757.39117.303719.397622.48
197622.48117.303719.067487.24
207487.24117.303718.727351.66
217351.66117.303718.387215.74
227215.74117.303718.047079.48
237079.48117.303717.706942.88
246942.88117.303717.366805.94
256805.94117.303717.016668.65
266668.65117.303716.676531.02
276531.02117.303716.336393.05
286393.05117.303715.986254.73
296254.73117.303715.646116.07
306116.07117.303715.295977.06
315977.06117.303714.945837.70
325837.70117.303714.595697.99
335697.99117.303714.245557.93
345557.93117.303713.895417.52
355417.52117.303713.545276.76
365276.76117.303713.195135.65
375135.65117.303712.844994.19
384994.19117.303712.494852.38
394852.38117.303712.134710.21
404710.21117.303711.784567.69
414567.69117.303711.424424.81
424424.81117.303711.064281.57
434281.57117.303710.704137.97
444137.97117.303710.343994.01
453994.01117.30379.993849.70
463849.70117.30379.623705.02
473705.02117.30379.263559.98
483559.98117.30378.903414.58
493414.58117.30378.543268.82
503268.82117.30378.173122.69
513122.69117.30377.812976.20
522976.20117.30377.442829.34
532829.34117.30377.072682.11
542682.11117.30376.712534.52
552534.52117.30376.342386.56
562386.56117.30375.972238.23
572238.23117.30375.602089.53
582089.53117.30375.221940.45
591940.45117.30374.851791.00
601791.00117.30374.481641.18
611641.18117.30374.101490.98
621490.98117.30373.731340.41
631340.41117.30373.351189.46
641189.46117.30372.971038.13
651038.13117.30372.60886.43
66886.43117.30372.22734.35
67734.35117.30371.84581.89
68581.89117.30371.45429.04
69429.04117.30371.07275.81
70275.81117.30370.69122.20
71122.20117.3000.310.00


ROI Summary
Total Additional Payment Paid 1540
Total Interest saved 174.56756
Effective ROI 11.3355558%

Sample Program Executions:

image1 image2