Function to create an amortization fund table in R
[This article was first published on Data R Value, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Function to create an amortization fund table.Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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[1] <<- 0
I[2] <<- R*i
CA[1] <<- R
SF[1] <<- 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
To leave a comment for the author, please follow the link and comment on their blog: Data R Value.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.