Simple Monte Carlo Taking Too Long

4 Ansichten (letzte 30 Tage)
Andrew Souphis
Andrew Souphis am 21 Mai 2019
Bearbeitet: KSSV am 21 Mai 2019
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

Akzeptierte Antwort

KSSV
KSSV am 21 Mai 2019
Bearbeitet: KSSV am 21 Mai 2019
  1. Don't print the result in workspace.
  2. Terminate the output using ;
  3. Initialize the arrays which are getting filled in loop.
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

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by