for loop is endless
이전 댓글 표시
Hello all,
I am trying to create a for loop for 10,000 iterations. I start by creating an empty vector which I then plug in into my for loop. The only problem is my for loop is not stopping and I have to force stop the script to run. Secondly, it seems that my forloop is just overwriting each iteration's computation and not appending it to the next row.
Below is an extract of my code
ST1 = 1:1:10000
%ST1 = zeros()
%Step5: Declaring empty ST2 row vector matrix for 20,000 simulations
ST2 = zeros(1,20000);
%Step5: Simulation of n = 10000 neutral paths
for n = 1:10000
ST1 = sadj*exp(r-0.5*(vol^2))*T+vol*sqrt(T)*randn(n);
end
%Step6: Compute the discounted cash flow for each path
CST1 = [1:10000]
for n = 1:10000
CST1 = exp(-r*T)*max(ST1(n)-K)
end
댓글 수: 2
Jan
2022년 5월 22일
There are 2 for loops in the code snippet. Which one do you mean?
Mahmoud Galal
2022년 5월 22일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!