# Function to create an amortization fund table in R

January 3, 2017
By

(This article was first published on Data R Value, and kindly contributed to R-bloggers)

Function to create an amortization fund table.
We establish the precision with which we want to work

options(digits = 7)

we say we do not want to work in scientific notation

options(scipen = 999)

We declare vectors to store the values of the different variables

I <- numeric();CA <<- numeric();SF <<- numeric()

We give values for the amount, number of periods and interest rate

M <- 2400000
n <- 50
i <- 3.7/100

We create function:

f.amort <- function(M,i,n) {

R <<- M*i/(((1 + i)**n)-1)
I <<- 0
I <<- R*i
CA <<- R
SF <<- R

for (k in 1:(n-1)) {

CA[k+1] <<- R + I[k+1]
SF[k+1] <<- SF[k] + CA[k+1]

if (k < n-1){
I[k+2] <<- SF[k+1]*i
}
}
}

f.amort(M, i, n)

tabla <- cbind(I,CA,SF)
rtotal <- R*n
totales <- c(rtotal,sum(I),sum(CA),000)
renta <- c(R, recursive=TRUE)

tabla <- cbind(renta, tabla)
tabla <- rbind(tabla, totales)
colnames(tabla) <- c(“Rent”,”Interest”,”
Accumulated Amount“, “Closing Balance“)

You can get the script in:
https://github.com/pakinja/-Financial-Mathematics-in-R/blob/master/AmortizationFund.r R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...