- Don't print the result in workspace.
- Terminate the output using ;
- Initialize the arrays which are getting filled in loop.
Simple Monte Carlo Taking Too Long
4 views (last 30 days)
Show older comments
Hello, I can't debug as to why my monte carlo simulation is taking forever. The code seems to be correct, but I am guessing the nested for is slowing down the simulation.
My simulation produces a 1000x252 matrix, and my code is:
i=1000
T=252
eps=normrnd(0,1,[i,T])
S0=2809
K=2750
for j=1:252
for c=1:1000
S(c,j)=S0*exp((.0295-.5*(.2^2))*.004+.0295*sqrt(.004)*eps(c,j))
end
end
for o=1:1000
payoff=max(0,S(k,252)-K)
end
0 Comments
Accepted Answer
KSSV
on 21 May 2019
Edited: KSSV
on 21 May 2019
i=1000 ;
T=252 ;
eps=normrnd(0,1,[i,T]) ;
S0=2809 ;
K=2750 ;
S = zeros(252,1000) ;
for j=1:252
for c=1:1000
S(c,j)=S0*exp((.0295-.5*(.2^2))*.004+.0295*sqrt(.004)*eps(c,j)) ;
end
end
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!