We have a stock with a Gaussian (normal) rate of return. The mean rate of return is \(9\)% and standard deviation is \(12\)%. This basically means that our stock will have a normal distribution of rate of return centered at 9. Function rnorm will generate values around 9 with standard deviation of 12 that are spread out like a normal distribution.
set.seed(1729)
# Generate 100 values
returns = rnorm(1:100, mean = 9, sd = 12)
# plot a histogram
hist(returns)
Vector returns contains 100 numbers with the mean \(9\) and stanndard deviation of \(12\). We can see that the returns are spread out like a normal distribution.
Now, assume our return is annual and we would like to see what our return will be in 4 years. We can start with randomly choosing (sampling) \(4\) numbers from the returns vector.
sample(returns,size = 4)
## [1] 1.307647 10.492049 -4.440902 10.150590
Above are our returns for years 1-4. Let’s do it again.
sample(returns,size = 4)
## [1] 8.144335 7.739717 -9.631079 23.731298
You can see that the returns are different this time. So which scenario should we anticipate. Why dont we consider a large number of scenarios. We can estimate the rate of return by sampling from the returns vector a large number of times say 10000 and then taking the mean for each year. This is a Monte Carlo simulation. Monte Carlo Simulation is repeated random sampling to obtain numerical results (from wikipeadia).
X = matrix(ncol = 4,nrow = 10000)
for(year in 1:4) {
# for each year sample the return 10000 times
for(i in 1:10000){
X[i,year] = sample(returns,1)
}
}
# show first 6 rows
head(X)
## [,1] [,2] [,3] [,4]
## [1,] 2.325729 -17.949140 7.739717 21.788331
## [2,] 2.141447 -10.704193 20.901110 20.311747
## [3,] 10.492049 -9.631079 12.458658 6.549687
## [4,] 15.688964 10.507150 -1.975553 -16.344384
## [5,] 10.492049 3.305106 16.445481 1.147742
## [6,] 9.344556 1.147742 26.296905 15.026501
Above is a dataset of \(10000\) rates of returns for each year. We can take the column means to see what we can expect for each year.
# Mean expected rate of return
apply(X,2,mean)
## [1] 9.036440 8.951381 8.845277 8.838054
We could sample a million times instead of \(10000\), adjust the mean and sd of the rate of return distribution or use other distributions. This let’s us ask what if questions and reduce the uncertainty of our stock portfolio.