Johannes Spiess
September 2017
The user interface of the app asks for three basic parameters
Additionaly, users can enter a start date of the loan to caclulate in which year (approximately) the loan will be paid off.
The following code part represents the core calculation of the app:
loan <- 300000 # Example for a loan of 300000
interest <- 5.5 # An interest rate of 5.5 percent
period <- 30 # A credit period of 30 years
# The formula below calculates the so called annuity, i.e. the necessary annual sum of back payments
loan * ((1+(interest/100))^period*(interest/100))/((1+(interest/100))^period-1)
[1] 20641.62
# A simple multiplication of the above by 1/12 yields the monthly annuity - which is seen to be even more graspable for users
1/12*loan * ((1+(interest/100))^period*(interest/100))/((1+(interest/100))^period-1)
[1] 1720.135
One feature of the app is to list and visualize (using a bar plot) how the annuities accumulate over time. We use a loop and the subsequently the function cumsum for that:
prob1 <- function(loan){
for(i in 2:(period+1))
loan[i] <- loan * ((1+(interest/100))^period*(interest/100))/((1+(interest/100))^period-1)
return(loan) }
x <- prob1(loan) # apply function for loan
x[1] <- 0 # replace first value with a 0
x <- cumsum(x) # accumulation of sums
return(x)
[1] 0.00 20641.62 41283.23 61924.85 82566.47 103208.08 123849.70
[8] 144491.32 165132.94 185774.55 206416.17 227057.79 247699.40 268341.02
[15] 288982.64 309624.25 330265.87 350907.49 371549.10 392190.72 412832.34
[22] 433473.95 454115.57 474757.19 495398.81 516040.42 536682.04 557323.66
[29] 577965.27 598606.89 619248.51
The Loan Calculator is …
We hope you find Loan Calculator helpful! Feel free to get in touch: jkhspiess@gmail.com