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.
/* 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
| Period | Beginning principal | Payment Amount | Extra Payment Amount | Total Interest | New Principal |
|---|---|---|---|---|---|
| 1 | 10000.00 | 117.30 | 37 | 25.00 | 9870.70 |
| 2 | 9870.70 | 117.30 | 37 | 24.68 | 9741.08 |
| 3 | 9741.08 | 117.30 | 37 | 24.35 | 9611.13 |
| 4 | 9611.13 | 117.30 | 37 | 24.03 | 9480.86 |
| 5 | 9480.86 | 117.30 | 37 | 23.70 | 9350.26 |
| 6 | 9350.26 | 117.30 | 37 | 23.38 | 9219.34 |
| 7 | 9219.34 | 117.30 | 37 | 23.05 | 9088.09 |
| 8 | 9088.09 | 117.30 | 37 | 22.72 | 8956.51 |
| 9 | 8956.51 | 117.30 | 37 | 22.39 | 8824.60 |
| 10 | 8824.60 | 117.30 | 37 | 22.06 | 8692.36 |
| 11 | 8692.36 | 117.30 | 37 | 21.73 | 8559.79 |
| 12 | 8559.79 | 117.30 | 37 | 21.40 | 8426.89 |
| 13 | 8426.89 | 117.30 | 37 | 21.07 | 8293.66 |
| 14 | 8293.66 | 117.30 | 37 | 20.73 | 8160.09 |
| 15 | 8160.09 | 117.30 | 37 | 20.40 | 8026.19 |
| 16 | 8026.19 | 117.30 | 37 | 20.07 | 7891.96 |
| 17 | 7891.96 | 117.30 | 37 | 19.73 | 7757.39 |
| 18 | 7757.39 | 117.30 | 37 | 19.39 | 7622.48 |
| 19 | 7622.48 | 117.30 | 37 | 19.06 | 7487.24 |
| 20 | 7487.24 | 117.30 | 37 | 18.72 | 7351.66 |
| 21 | 7351.66 | 117.30 | 37 | 18.38 | 7215.74 |
| 22 | 7215.74 | 117.30 | 37 | 18.04 | 7079.48 |
| 23 | 7079.48 | 117.30 | 37 | 17.70 | 6942.88 |
| 24 | 6942.88 | 117.30 | 37 | 17.36 | 6805.94 |
| 25 | 6805.94 | 117.30 | 37 | 17.01 | 6668.65 |
| 26 | 6668.65 | 117.30 | 37 | 16.67 | 6531.02 |
| 27 | 6531.02 | 117.30 | 37 | 16.33 | 6393.05 |
| 28 | 6393.05 | 117.30 | 37 | 15.98 | 6254.73 |
| 29 | 6254.73 | 117.30 | 37 | 15.64 | 6116.07 |
| 30 | 6116.07 | 117.30 | 37 | 15.29 | 5977.06 |
| 31 | 5977.06 | 117.30 | 37 | 14.94 | 5837.70 |
| 32 | 5837.70 | 117.30 | 37 | 14.59 | 5697.99 |
| 33 | 5697.99 | 117.30 | 37 | 14.24 | 5557.93 |
| 34 | 5557.93 | 117.30 | 37 | 13.89 | 5417.52 |
| 35 | 5417.52 | 117.30 | 37 | 13.54 | 5276.76 |
| 36 | 5276.76 | 117.30 | 37 | 13.19 | 5135.65 |
| 37 | 5135.65 | 117.30 | 37 | 12.84 | 4994.19 |
| 38 | 4994.19 | 117.30 | 37 | 12.49 | 4852.38 |
| 39 | 4852.38 | 117.30 | 37 | 12.13 | 4710.21 |
| 40 | 4710.21 | 117.30 | 37 | 11.78 | 4567.69 |
| 41 | 4567.69 | 117.30 | 37 | 11.42 | 4424.81 |
| 42 | 4424.81 | 117.30 | 37 | 11.06 | 4281.57 |
| 43 | 4281.57 | 117.30 | 37 | 10.70 | 4137.97 |
| 44 | 4137.97 | 117.30 | 37 | 10.34 | 3994.01 |
| 45 | 3994.01 | 117.30 | 37 | 9.99 | 3849.70 |
| 46 | 3849.70 | 117.30 | 37 | 9.62 | 3705.02 |
| 47 | 3705.02 | 117.30 | 37 | 9.26 | 3559.98 |
| 48 | 3559.98 | 117.30 | 37 | 8.90 | 3414.58 |
| 49 | 3414.58 | 117.30 | 37 | 8.54 | 3268.82 |
| 50 | 3268.82 | 117.30 | 37 | 8.17 | 3122.69 |
| 51 | 3122.69 | 117.30 | 37 | 7.81 | 2976.20 |
| 52 | 2976.20 | 117.30 | 37 | 7.44 | 2829.34 |
| 53 | 2829.34 | 117.30 | 37 | 7.07 | 2682.11 |
| 54 | 2682.11 | 117.30 | 37 | 6.71 | 2534.52 |
| 55 | 2534.52 | 117.30 | 37 | 6.34 | 2386.56 |
| 56 | 2386.56 | 117.30 | 37 | 5.97 | 2238.23 |
| 57 | 2238.23 | 117.30 | 37 | 5.60 | 2089.53 |
| 58 | 2089.53 | 117.30 | 37 | 5.22 | 1940.45 |
| 59 | 1940.45 | 117.30 | 37 | 4.85 | 1791.00 |
| 60 | 1791.00 | 117.30 | 37 | 4.48 | 1641.18 |
| 61 | 1641.18 | 117.30 | 37 | 4.10 | 1490.98 |
| 62 | 1490.98 | 117.30 | 37 | 3.73 | 1340.41 |
| 63 | 1340.41 | 117.30 | 37 | 3.35 | 1189.46 |
| 64 | 1189.46 | 117.30 | 37 | 2.97 | 1038.13 |
| 65 | 1038.13 | 117.30 | 37 | 2.60 | 886.43 |
| 66 | 886.43 | 117.30 | 37 | 2.22 | 734.35 |
| 67 | 734.35 | 117.30 | 37 | 1.84 | 581.89 |
| 68 | 581.89 | 117.30 | 37 | 1.45 | 429.04 |
| 69 | 429.04 | 117.30 | 37 | 1.07 | 275.81 |
| 70 | 275.81 | 117.30 | 37 | 0.69 | 122.20 |
| 71 | 122.20 | 117.30 | 0 | 0.31 | 0.00 |
ROI Summary
Total Additional Payment Paid 1540
Total Interest saved 174.56756
Effective ROI 11.3355558%