- 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
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
KSSV
il 21 Mag 2019
Modificato: KSSV
il 21 Mag 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 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!