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

 채택된 답변

KSSV
KSSV 2019년 5월 21일
편집: KSSV 2019년 5월 21일

0 개 추천

  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

추가 답변 (0개)

질문:

2019년 5월 21일

편집:

2019년 5월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by