Post by kokenge on Mar 18, 2008 9:58:36 GMT -5
A very simple Mortgage Amortization schedule.
' ------------------------------------------------------------------------------------------
' Monthly Mortgage Payment Calculator
' ------------------------------------------------------------------------------------------
' 52 - Weekly
' 26 - Biweekly
' 12 - Monthly
' 6 - Bimonthly
TITLEBAR "Mortgage Amortization"
period = 12
function calculateMortgage(balance,rate,term)
global period
N = term * period
I = (rate / 100) / period
v = (1 + I) ^ N
t = (I * v) / (v - 1)
calculateMortgage = balance * t
end function
html "<h1>Mortgage Calculator</h1><HR>"
html "<TABLE><TR><TD align=right>"
html "Loan balance:</TD><TD>"
textbox #b,""
html "</TD></TR><TR><TD align=right>"
html "Interest rate:</TD><TD>"
textbox #r,""
html "</TD></TR><TR><TD align=right>"
html "Loan term (Years):</TD><TD>"
textbox #t,""
html "</TD></TR><TR><TD align=right>"
html "Period:</TD><TD>"
dim p$(4)
p$(1) = "12: - Monthly"
p$(2) = "06: - Bimonthly"
p$(3) = "52: - Weekly"
p$(4) = "26: - Biweekly"
listbox #p,p$(),4
html "</TD></TR><TR><TD align=center colspan=2>"
link #calc,"Calculate", [calc]
html " "
link #ex, "Exit", [exit]
html "</TD></TR></TABLE>"
wait
[exit]
cls
wait
[calc]
balance = val(#b contents$())
rate = val(#r contents$())
term = val(#t contents$())
per$ = #p selection$()
if per$ = "" then per$ = p$(1) ' if no input use default
period = val(left$(per$,2))
cls
html "<table>"
html "<tr><td bgcolor=tan>Period:</td><td align=right>";per$;"</td></tr>"
pay = calculateMortgage(balance,rate,term)
pay = val(using("#########.##",pay))
html "<tr><td bgcolor=tan>Monthly payment:</td><td align=right>";pay;"</td></tr>"
html "<tr><td bgcolor=tan>Total interest:</td><td align=right>";((term * pay * period) - balance);"</td></tr>"
html "</table>"
html "<br/><br/>"
html "<table border=1>"
html "<tr align=center bgcolor=tan><td>Month</td><td>Principial</td><td>Interest</td><td>Payment</td></tr>"
for i = 0 to term * period
tmp = ((pay) - (balance * (rate / 100 / period)))
diff = val(using("########.##",tmp))
int = balance * rate / 100 / period
int = val(using("########.##",int))
princ = balance - diff
balance = int(balance + .5)
html "<tr><td align=center>";i;"</td><td> ";balance;"</td><td> ";int;"</td><td> ";pay;"</td></tr>"
balance = princ
next i
html "</table>"
wait