CS代写 title: “Endowment Sim”

title: “Endowment Sim”
output: html_document

“`{r setup, include=FALSE}

Copyright By PowCoder代写 加微信 powcoder

knitr::opts_chunk$set(echo = TRUE)

The Director of Investments for a small, private K-12 school manages an endowment with a current balance of $538,000. The funds are invested in a portfolio whose annual returns varies and can be represented as a normally distributed random variable with a mean of 6% and a standard deviation of 2%.

A new scholarship is being created as a memorial to a distinguished alumna. The legal terms of the endowment require the Director of Investments to determine a constant scholarship payment amount from the endowment that, if made at the end of each of the next 15 years, would result in only a 5% chance of the endowment’s ending value dropping below its current value. Create a simulation model to make a recommendation for a scholarship amount that achieves this goal.

##Simulating Returns

BeginBalance <- 538000 numYears <- 15 exp_return <- .06 sd_return <- .02 Balance <- data.frame(Begin = numeric(), Return = numeric(), Earning = numeric(), End = numeric()) for (i in 1:numYears){ if(i == 1){ Balance[i, "Begin"] <- BeginBalance Balance[i, "Begin"] <- Balance[i-1, "End"] Balance[i, "Return"] <- rnorm(1,exp_return,sd_return) Balance[i, "Earning"] <- Balance[i, "Return"] * Balance[i, "Begin"] Balance[i, "End"] <- Balance[i, "Begin"] + Balance[i, "Earning"] CAGR <- (Balance[nrow(Balance), "End"] / Balance[1, "Begin"])^(1/numYears) - 1 sd(Balance$Return) ##Simulation Trials numYears <- 15 numTrials <- 1000 BeginBalance <- 538000 exp_return <- .06 sd_return <- .02 EndowmentSim <- NULL for (i in 1:numTrials){ EndowmentSimYear <- c(BeginBalance, rep(0,15)) for (j in 2:(numYears + 1)){ EndowmentSimYear[j] <- EndowmentSimYear[j-1] *(1+rnorm(1,exp_return,sd_return)) EndowmentSim <- rbind(EndowmentSim, EndowmentSimYear) colnames(EndowmentSim) <- paste("Year", 0:15) rownames(EndowmentSim) <- 1:nrow(EndowmentSim) head(EndowmentSim) hist(EndowmentSim[ , "Year 15"], breaks = 30) range(EndowmentSim[ ,"Year 15"]) matplot(t(EndowmentSim[1:100, ]), type = "l", ylim = c(0,1600000), xaxt = "n") title(main = "Endowment Balance by Year: 100 Sims") axis(1, at = 1:16, labels = colnames(EndowmentSim)) ##Scholarship numYears <- 15 numTrials <- 1000 BeginBalance <- 538000 exp_return <- .06 sd_return <- .02 SimOutput <- NULL ScholarshipRange <- seq(22000, 32000, 500) for (k in 1:length(ScholarshipRange)){ EndowmentSim <- NULL SimOutputYear <- NULL for (i in 1:numTrials){ EndowmentSimYear <- c(BeginBalance, rep(0,15)) for (j in 2:(numYears + 1)){ EndowmentSimYear[j] <- EndowmentSimYear[j-1] *(1+rnorm(1,exp_return,sd_return)) - ScholarshipRange[k] EndowmentSim <- rbind(EndowmentSim, EndowmentSimYear) colnames(EndowmentSim) <- paste0("Year", 0:15) rownames(EndowmentSim) <- 1:nrow(EndowmentSim) SimOutputYear <- c(ScholarshipRange[k], sum(EndowmentSim[ , 16] < BeginBalance) / nrow(EndowmentSim)) SimOutput <- rbind(SimOutput, SimOutputYear) rownames(SimOutput) <- 1:nrow(SimOutput) colnames(SimOutput) <- c("Scholarship Amt", "Prob of loss in principal") 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com