필터 지우기
필터 지우기

Recursion, stock simulation

조회 수: 1 (최근 30일)
N/A
N/A 2017년 8월 18일
답변: Jacob Ward 2017년 9월 6일
I am new to Matlab, could you help me out with automating this process:
S_1 = S_0*(1+r*dt+sigma*a*normrnd(0,1))
S_2 = S_1*(1+r*dt+sigma*a*normrnd(0,1))
S_3 = S_2*(1+r*dt+sigma*a*normrnd(0,1)) ... ... ...
Thanks
  댓글 수: 1
José-Luis
José-Luis 2017년 8월 18일
I would start by not using numbered variables and storing everything in an array.
After that, your problem becomes trivial.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jacob Ward
Jacob Ward 2017년 9월 6일
Instead of giving each variable a name with a different number, store all of these things in one array. So instead of S_0, S_1, S_2, and S_3, use one variable S that has 4 different elements which you can access like this: S(1),S(2),S(3), and S(4).
If you define your variables in this way, this problem becomes easy:
S(1) = constant;
for i = 2:n
S(i) = S(i-1)*(1+r*dt+sigma*a*normrnd(0,1))
end
Simply replace n with how many times you would like to perform the iteration and you are good to go.

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by