Simple mortgage calculator (iPhone & up)

Post Reply
Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Simple mortgage calculator (iPhone & up)

Post by Henko »

I needed a simple mortgage calculator, which also took into account the tax facility as used in The Netherlands. They exist on some Dutch internet sites, but I am not sure about where what data goes if you use such on-line tools.
This simple program is based on an annuïty loan. Inputs are the loaned capital, the (yearly) interest rate in %, and the number of years for the loan. Output is the monthly payment, which is constant during the loan period.
Dutch people might enter the additional field about the yearly taxable income to see the effect of the tax deduction facility (gross -> net payment). It is funny too see how higher incomes result in lower net payments for a mortgage loan.
Don't forget to confirm field entries by using the Enter key. Only then the changed data in the fields will be transferred to the internal variables.
The app fits on iPhones.
The user interface is simple but effective. I strongly prefer simple programming rather than a stylish look. ;)

Code: Select all

option base 1
dim valid(3)
app_init
new_calc: changed=0
no_input: slowdown
if fc("cap") then       ' enter the needed capital 
  capital=field_text$("cap") ! changed=1
  if capital>0 then valid(1)=1 else valid(1)=0
  end if
if fc("int") then       ' enter the yearly interest rate in %
  yrate=field_text$("int")/100 ! changed=1
  if yrate>0 then valid(2)=1 else valid(2)=0
  end if
if fc("per") then       ' enter the loan period in years
  years=field_text$("per") ! changed=1
  if years>0 then valid(3)=1 else valid(3)=0
  end if
if fc("inc") then       ' enter the yearly (taxable) income
  income=field_text$("inc") ! changed=1
  end if
if not changed then no_input  ' check for changes and valid data
for i=1 to 3 ! if valid(i)=0 then no_input ! next i

periods=12*years    ' the calculation is based on monthly periods
mrate=(1+yrate)^(1/12)-1
gross=mrate*capital/(1-(1+mrate)^(-periods))
tax1=income_tax(income) ! tax2=income_tax(income-yrate*capital)
net=gross-(tax1-tax2)/12
button "gpay" text n2a$(gross,8,2)
button "npay" text n2a$(net,8,2)
goto new_calc
end

def app_init
graphics ! graphics clear ! draw color 0,0,0
draw text "Capital ............." at 20,20
field "cap" text "0" at 70,40 size 200,30
draw text "interest % .........." at 20,80
field "int" text "0" at 70,100 size 200,30
draw text "# of years .........." at 20,140
field "per" text "0" at 70,160 size 200,30
draw text "taxable income/yr ..." at 20,200
field "inc" text "0" at 70,220 size 200,30
draw text "gross payment/month ." at 20,280
button "gpay" title "0" at 70,300 size 200,30
draw text "net   payment/month ." at 20,340
button "npay" title "0" at 70,360 size 200,30
end def

def income_tax(income)  ' for The Netherlands, year 2015
if income<0 then return 0
restore
read disc1,disc2,perc1,perc2,perc3
data 19822,37763, 0.365,0.42,0.52
if income<=disc1 then ! tax=perc1*income ! return tax ! end if
tax=perc1*disc1 ! income-=disc1
if income<=disc2 then ! tax+=perc2*income ! return tax ! end if
tax+=perc2*disc2 ! income-=disc2
tax+=perc3*income ! return tax
end def

def fc(name$) = field_changed(name$)

def n2a$(num,lang,dec)
b$="               "
fac=10^dec ! num$=floor(fac*num+.5)/fac
tot=lang-len(num$) ! if tot<1 then tot=1
return substr$(b$,1,tot) & num$
end def

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Simple mortgage calculator (iPhone & up)

Post by rbytes »

It works well. Thanks.
The only thing that gets me down is gravity...

Post Reply