Page 1 of 1

A bit dull: Compound Interest Algorithm

Posted: Mon Apr 24, 2006 3:30 pm
by naw
Hi,

Sorry - this is a bit dull :-\ I did a bit of research on the net and I think this is a good formula for calculating Compound Interest:

L = £1000 Loan amount
I = 5% Interest %%
R = 4 Recalculations PA
Y = 3 Years remaining

L * ( 1 + I / R ) ^ ( Y * R ) = 1000 * (1 + 5 / 4) ^ ( 3 * 4 )


So If you took out a £1000 loan at 5% over 5 years with quarterly recalculations, the amount to repay should be £1,160.75

- So, does anyone know if this is a valid calculation for Compound Interest?

Also, I think that if you make a £27.78 monthly capital repayment throughout the 3 year period (and recalulate annually), then the actual amount repaid would be £1,100.05

ie:

Year 1 loan amount is £1000, Year 2 loan amount is £666.67, Year 3 loan amount is £333.33.

Interest Payment for Year 1 would be 12*£4.47=£53.64, Year 2 would be 12 * £2.60=£31.20 and Year 3 would be 12*£1.27=£15.24

Does this make sense? Do I understand what I'm doing?

Any comments would be very welcome :-)

Posted: Mon Apr 24, 2006 5:36 pm
by TerryHough
Maybe you want to look at
http://www.purebasic.fr/english/viewtopic.php?t=12285
again.

You visited that topic back in 2004

or go to here to download a program to check your work and see
an amortization schedule.
http://elfecc.no-ip.info/Freeamort.htm

Terry

Posted: Mon Apr 24, 2006 6:17 pm
by naw
;-) Yes indeed...

I'm just curious as to wether or not I really do understand it or not.

I found a few calculators around, but most have slightly different inputs and produce different answers. ie some assume a single calculation period each year, others allow many recalculations.

So having looked at various formulae and calculators that do almost the same thing, I came up with my version - I'm just not 100% sure if I'm right...

Posted: Mon Apr 24, 2006 7:28 pm
by Bonne_den_kule
L*(1+I)^Y
Not sure if it is this you are looking for.

Posted: Mon Apr 24, 2006 11:37 pm
by naw
@Bonne_den_kule
Hi, Yes - essentially it is - but I think that L*(1+I)^Y assumes a single recalculation per year - some loans do continual recalculations of the interest (though I assume that in reality if you only pay monthly, then a monthly recalculation is all you need)...
...Just not sure if my maths are right -or- if mine is a legitimate algorithm that the banks use.

Posted: Sat Apr 29, 2006 9:35 am
by netmaestro
Here in Canada mortgage payments are paid monthly, biweekly or even weekly but the interest is always compounded semi-annually. Makes for a slightly more complex formula, I can post it if anyone's "interested" (pun shamelessly stretched for)

Posted: Sat Apr 29, 2006 9:24 pm
by josku_x
Please post it, it could be useful for something.

Posted: Sun Apr 30, 2006 9:56 pm
by netmaestro
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

Posted: Tue May 02, 2006 1:20 pm
by naw
@netmaestro,

Hi, thanks for the post - doesnt compile with PB3.9, so I downloaded PB4.11B and compiles fine. Unfortunately, get lots of "Array Index Out of Bounds" Errors...

I used the following inputs:
Loan Amt: 100000
Int Rate: 5
Years: 20
Payments: 12
Compunds: 12

Your Payments are: 41666.67
Increase Amount (y/n)?: n

If I answer "y" to Increase Amount and provide a value of 41666.68, then everything is ok...

Posted: Tue May 02, 2006 1:28 pm
by netmaestro
5 for the interest rate makes for 500% interest, which I believe is only available in Sicily. Maybe Chicago. You have to use 0.05 for 5 percent, see the example shown on the data entry screen. Using that I get payments of $659.96.

Posted: Tue May 02, 2006 2:29 pm
by Dare2
netmaestro wrote:.. is only available in Sicily. Maybe Chicago.
lol. :)

Posted: Tue May 02, 2006 2:38 pm
by naw
Haha - my bad ;-)