Reputation: 1
Background: We run a simulation which creates a matrix as an output. This output is then put into a function (with two variables) which creates a matrix/vector as an output.
Is there an easy way to optimize the function's parameters so that the output vector contains the maximum output possible?
This produces the simulated matrix:
sim=1000
subp=12
set.seed(1)
eps.m <- matrix(rnorm(sim*subp), sim, subp, byrow=TRUE)
mü5=0.0003934473
sigma5=0.07147787
r.m<-mü5-sigma5^2/2 + sigma5*eps.m
S.m <- matrix(0,sim,subp+1)
S.m[,1] <- 1000
for (j in 2:13) S.m[,j]<-S.m[,j-1]*exp(r.m[,j-1])
Some variables like "mü5", "sigma5" are defined a bit before the simulation, if you need them please let me know.
And this is the mentioned function dependent on "mu" and "b":
CPPIopt <- function(mu,b) {
FT <- 650000
W0 <- 1000000
T0 <- 1
m <- 12
rf <- log(1.01)
SIM<-matrix(0,nrow(S.m),m+1)
SIM[,1] <- W0
Tt.T[1] <- T0
for(i in 2:(m+1)) {
Wt <- SIM[,i-1]
Tt.T[i] <- Tt.T[i-1]-(T0/m)
Ft[i] <- FT*exp((-rf)*Tt.T[i])
Ct[i] <- max(Wt-Ft[i], 0)
Xr.t[i] <- min(mu*Ct[i],b*Wt)
Xf.t[i] <- W0-Xr.t[i]
SIM[,i] <- (Xr.t[i]*S.m[,i])/S.m[,i-1] + Xf.t[i]*exp(rf/m)}
return(SIM[,13])
}
Unfortunately I'm a beginner in R and it's my first post, so please have mercy with me.
Any kind of help or information to the problem would be greatly appreciated, big thanks in advance!
Upvotes: 0
Views: 100