reps <- as.numeric(par1) policies <- as.numeric(par2) prem <- as.numeric(par3) cost <- as.numeric(par4) prob <- as.numeric(par5) if (par6 == 'TRUE') Poisson <- TRUE if (par6 == 'FALSE') Poisson <- FALSE gross.profit <- 1:policies gross.profit.rate <- 1:reps if (Poisson==T) { for (j in 1:reps) { totalcost=cost*rpois(policies,prob) gross.profit=prem-totalcost gross.profit.rate[j]=sum(gross.profit)/policies } } if (Poisson==F){ for (j in 1:reps) { totalcost=cost*rbinom(policies,1,prob) gross.profit = prem-totalcost gross.profit.rate[j] = sum(gross.profit)/policies } } risk <- 100 * (length (gross.profit.rate[gross.profit.rate < 0]))/reps print(risk) avgprofit <- format(mean(gross.profit.rate), digits = 5) sdprofit <- format(sd(gross.profit.rate), digits = 5) bitmap(file='test1.png') stripchart(gross.profit.rate, method = 'stack', main = main, xlab = xlab, ylab = ylab, col = 'blue', xlim = c( -800, 1300), at=0.1) stripchart(gross.profit.rate[gross.profit.rate<0], method = 'stack', col = 'red', add = TRUE, at=0.1) text(700, 1.55, 'number of policies = ',adj=1) text(900, 1.55, policies) text(700, 1.4, 'number of simulations = ',adj=1) text(900, 1.4, reps) text(700, 2.0, 'mean of gross profit/policy = ',adj=1) text(800, 2.0, '$') text(900, 2.0, avgprofit) text(700, 1.7, 'risk of loss = ',adj=1) text(875, 1.7, round(risk,)) text(975, 1.7, '%') text(700, 1.85, 'SD of gross profit/policy = ',adj=1) text(800, 1.85, '$') text(900, 1.85, sdprofit) dev.off() x<-rnorm(100) load(file='createtable') a<-table.start() a<-table.row.start(a) a<-table.element(a,'Summary Statistics',2,TRUE) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'Number of policies',header=TRUE) a<-table.element(a,policies) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'Number of simulations',header=TRUE) a<-table.element(a,reps) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'Mean of gross profit per policy in USD',header=TRUE) a<-table.element(a,avgprofit) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'Risk of loss in percent',header=TRUE) a<-table.element(a, round(risk,0) ) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'SD of gross profit per policy',header=TRUE) a<-table.element(a,sdprofit) a<-table.row.end(a) a<-table.end(a) table.save(a,file='mytable.tab')
|