mortgage <- function(P, r, year, py){
m <- year*12;
Ei <- rep(0,m);
mr <- r/12;
E <- P*mr/((1+mr)^m -1);
pmt <- P*mr+E;
for(i in 1:m) Ei[i]<-E*(1+mr)^(i-1);
Ii <- pmt-Ei;
cat(year, "year at", r*100, "%\n");
cat("Monthly Payment:", pmt, "\n");
cat("Total Payment:", pmt*m, ", Total Interest:", pmt*m-P, "\n");
cat("Total Principal:", sum(Ei[1:(12*py)]),
", Total Interest:", sum(Ii[1:(12*py)]),"(After", py, "years)\n");
}
P <- 210000 # principal
r <- 0.05625 # interest rate
year <- 15 # loan period
py <- 5 # short term
mortgage(P,r,year,py)
No comments:
Post a Comment