Use replicate():
N = 10000
results = replicate(N, mvrnorm(n = 30, mu = mu, Sigma = sigma))
print(head(results, 10))
Question
I have three variables A, B, and C with a time-series of returns. I would to run a random sampling using mvrnorm
from package MASS
, to generate 30 values for A, B and C.
I would like to be able to repeat this operation 10000 times, each time generating 30 values for A, B, C.
I execute one iteration using:
sim.ret = mvrnorm(n = 30, mu = mu, Sigma = sigma)
How can I run this function 10,000 times? I then use the result of each iteration to do some computations.
Any help would be appreciated! Thanks.
Solution
Use replicate():
N = 10000
results = replicate(N, mvrnorm(n = 30, mu = mu, Sigma = sigma))
print(head(results, 10))