I have a function that I would like to find the minimal value
start.capital = 2000000
target.capital = 49594660
monthly.inflation = 0.002
monthly.deposits = 50000
n.obs = 240
fn<-function(monthly.mean.return,
start.capital,
monthly.inflation,
monthly.deposits,
n.obs,
target.capital){
#monthly.mean.return = annual.mean.return / 12
#monthly.inflation = annual.inflation / 12
req = matrix(start.capital, n.obs+1, 1)
for (a in 1:n.obs) {
req[a + 1, ] = req[a, ] * (1 + monthly.mean.return - monthly.inflation) + monthly.deposits
}
ending.value=req[nrow(req),]
value<-target.capital - ending.value
return(value)
}
I would like to minimize "monthly.mean.return". The correct answer is 0.01 but I am getting big numbers...
I am trying:
optimize(f=fn,
monthly.mean.return,
start.capital,
monthly.inflation,
monthly.deposits,
n.obs,
target.capital,
lower=0)
Any ideas?