```
#> # Calculate a GBM - mu and sigmna are based on the respective market scenario
gbm = function(nsim = 25, t = 1, mu = 0.07, sigma = 0.3, S0 = 100, n = 250){
# number of time steps between time = 0 and time = t by time step length dt
time = seq.default(from = 0, to = t, length.out = t*n + 1)
# define the Wiener process between time = 0 and time = t for nsim simulations
W = matrix(
replicate(nsim, cumsum(c(0, sqrt(1/n) * rnorm( length(time) - 1 )))),
nrow = length(time), ncol = nsim, byrow = FALSE)
# fill the paths via analytical solution
S = S0 * exp( (mu - 0.5*sigma^2) * time + sigma * W)
S = ts(S, start = 0, deltat = n)
return(S)
}
# Assigning an object to the output matrix of the gbm() function
stockprices = gbm()
View(stockprices)
# Calculating the returns
Returns = stockprices
Returns[,1:dim(Returns)[2]] = NA
for (j in 1:dim(Returns)[2]) {
for(i in 2:nrow(Returns)){
Returns[i,j] = (stockprices[i,j]-stockprices[i-1,j])/stockprices[i-1,j]
}
}
# Plotting the simulation of the stock prices
matplot(
gbm(nsim = 25, t = 1, mu = 0.07, sigma = 0.3, S0 = 100, n = 250),
type = "l",
ylab = "",
lty = 1:5,
lwd = 0.5) <- here´´´
```

This is the code I used to generate 250 stock prices based on the Geometric Brownian motion and to calculate the returns of those stock prices. Now I want to calculate the expected utility of those returns. I would appreciate good advice on how to do this, how to start, what the steps are etc. I found a few examples which did not really help me. One example said that the three steps are to infer predictors, to define a utility function and to make a decision that maximizes Expected Utility. But my understanding of my specific problem is that I do not have to predict anything because I have calculated exact returns.