문제

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.

도움이 되었습니까?

해결책

Use replicate():

N = 10000
results = replicate(N, mvrnorm(n = 30, mu = mu, Sigma = sigma))
print(head(results, 10))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top