Here is a program that will work for all payment frequencies, compound frequencies and increased payment levels for open loans. Run some test numbers through it and see the remarkable effect of paying just 20 or 30 dollars more than the calculated payment. It knocks many payments off the life of the loan!
Code: Select all
; Compound interest calculations
; By netmaestro April 30, 2006
OpenConsole()
EnableGraphicalConsole(1)
ConsoleLocate(0,2)
PrintN(" Loan Amount-----> eg 100000")
PrintN(" Interest Rate---> eg 0.0625 for 6 1/4 percent")
PrintN(" Years of Loan---> eg 25")
PrintN(" Payments/Year---> eg 12, or 52 for weekly, any period works")
PrintN(" Compounds/Year--> eg 12, or 2 for semi-annual, or same as frequency")
ConsoleLocate(19,2): p.d = ValD(Input())
ConsoleLocate(19,3): j.d = ValD(Input()) : If j>1 : j/100 : EndIf
ConsoleLocate(19,4): y.l = Val(Input())
ConsoleLocate(19,5): f.l = Val(Input())
ConsoleLocate(19,6): m.l = Val(Input())
; calculate payment
a.d = p * (Pow(1+j/m, m/f) - 1) / (1 - Pow(1+j/m,-y*m))
ConsoleLocate(0,8)
PrintN("Your Payments are: "+StrD(a,2))
Print("Would you like to increase this amount (y=yes): ")
yn.s=Input()
If UCase(yn)="Y"
newa.d = 0
While newa < a
ConsoleLocate(0,11):Print("Enter new payment: ")
ConsoleLocate(19,11)
newa.d = ValD(Input())
Wend
a=newa
newpayment = #True
Else
newpayment = #False
EndIf
numpmts.l=y*f
Dim schedule.s(numpmts+1,5)
If newpayment
i=0
While p>1
i+1
int.d = p * (Pow(1+j/m, m/f) - 1)
pri.d = a-int
p - pri
If a<p
schedule(i,0) = RSet(Str(i)+":",5)
schedule(i,1) = RSet(StrD(a,2),7)
schedule(i,2) = RSet(StrD(int,2),9)
schedule(i,3) = RSet(StrD(pri,2),9)
schedule(i,4) = RSet(StrD(Abs(p),2),10)
Else
p=p+p*j/12
If Abs(p-a)<1
p=a
EndIf
schedule(i,0) = RSet(Str(i)+":",5)
schedule(i,1) = RSet(StrD(a,2),7)
schedule(i,2) = RSet(StrD(int,2),9)
schedule(i,3) = RSet(StrD(pri,2),9)
schedule(i,4) = RSet(StrD(Abs(p),2),10)
int = p*j/12
pri = p-int
p=0
i+1
schedule(i,0) = RSet(Str(i)+":",5)
schedule(i,1) = RSet(Trim(schedule(i-1,4)),7)
schedule(i,2) = RSet(StrD(int,2),9)
schedule(i,3) = RSet(StrD(pri,2),9)
schedule(i,4) = RSet(StrD(Abs(p),2),10)
EndIf
Wend
Else
i=0
While p>1
i+1
int.d = p * (Pow(1+j/m, m/f) - 1)
pri.d = a-int
p - pri
schedule(i,0) = RSet(Str(i)+":",5)
schedule(i,1) = RSet(StrD(a,2),7)
schedule(i,2) = RSet(StrD(int,2),9)
schedule(i,3) = RSet(StrD(pri,2),9)
schedule(i,4) = RSet(StrD(Abs(p),2),10)
Wend
EndIf
ConsoleLocate(0,13)
If newpayment
PrintN("Payments are adjusted from "+Str(f*y)+" to "+Str(i))
PrintN("Your last payment will be "+schedule(i,1))
PrintN("")
EndIf
PrintN("Data copied to clipboard")
PrintN("")
Print("Hit y to see a schedule, any other key to quit: ")
see.s = Input()
If UCase(see)="Y"
CloseConsole()
Gosub window
EndIf
out$=""
i=1
While schedule(i,0)<>""
out$+schedule(i,0)+schedule(i,1)+" "+schedule(i,2)+" "+schedule(i,3)+" "+schedule(i,4)+#CRLF$
i+1
Wend
SetClipboardText(out$)
End
window:
OpenWindow(0,0,0,445,600,"Amortization Schedule",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ListIconGadget(0,0,0,445,570,"Payment",120,#PB_ListIcon_GridLines|#PB_ListIcon_MultiSelect|#PB_ListIcon_FullRowSelect)
AddGadgetColumn(0,1,"Interest",100)
AddGadgetColumn(0,2,"Principal",100)
AddGadgetColumn(0,3,"Remaining",100)
LoadFont(0,"Courier New",10,#PB_Font_HighQuality)
SetGadgetFont(0,FontID(0))
i=1
While schedule(i,0)<>""
out$=schedule(i,0)+schedule(i,1)+Chr(10)+schedule(i,2)+Chr(10)+schedule(i,3)+Chr(10)+schedule(i,4)
AddGadgetItem(0,-1,out$)
i+1
Wend
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
Return