library(FinancialMath) library(ggplot2) options(width=200) df=read.csv("./cf.csv",header=FALSE) df$rem = df$V3 - df$V2 df$int = df$V2 * df$V3 df=df[complete.cases(df), ] for (i in c(1:length(df[,1]))){ df[i,]$int = as.numeric(paste( unlist(amort.table(Loan=df[i,]$V7,n=df[i,]$rem,i=((df[i,]$V5/100)/12))[2]))[3]) } df$pay = df$V2 * df$V3 for (i in c(1:length(df[,1]))){ df[i,]$pay = as.numeric(paste( unlist(amort.table(Loan=df[i,]$V7,n=df[i,]$rem,i=((df[i,]$V5/100)/12))[1]))[1]) } df$ratio = (df$V7)/(df$int) #df=df[!(df$V3<10),] #df=df[!(df$V7>100),] #df2=df[order(as.Date(df$V9), decreasing = FALSE), ] df2=df[order(df$ratio, decreasing = FALSE), ] head(df2,n=100) mean(df$ratio) #head(df2,n=1000) #as.numeric(paste( unlist(amort.table(Loan=200,n=59,i=((10/100)/12))[2]))[3]) pdf("cf2.pdf", width=10, height=5) ggplot(df, aes(x=ratio)) + geom_density() #scale_x_continuous(limits=c(-10,40)) dev.off()