- 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 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
KSSV
am 21 Mai 2019
Bearbeitet: KSSV
am 21 Mai 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 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!