Simple simulation of stock price

2 Ansichten (letzte 30 Tage)
N/A
N/A am 18 Aug. 2017
Kommentiert: N/A am 18 Aug. 2017
I am new with MATLAB. Could you help out with simulating X amount of what is inside the loop?
r = 0.02;
sigma = .2;
S_0 = 10;
dt = 1/4000;
wp = sqrt(dt);
S_1 = S_0*(1+r*dt+sigma*wp*normrnd(0,1));
for i = 1:1000
S_1 = S_1*(1+r*dt+sigma*wp*normrnd(0,1));
end
disp(S_1)
  1 Kommentar
Image Analyst
Image Analyst am 18 Aug. 2017
What do you mean by "X amount"? I don't see any variable X in the code either. And by "what is inside the loop" do you mean S_1? If X is some fraction, then X amount of S_1 is simply X*S_1.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Kuifeng
Kuifeng am 18 Aug. 2017
In the loop, does this answer to your question?
for i = 1:1000
S_1(i+1) = S_1(i)*(1+r*dt+sigma*wp*normrnd(0,1));
end
  1 Kommentar
N/A
N/A am 18 Aug. 2017
Thanks, These three lines generate stock price after 1000 steps. I need to generate, for example, 10000 of these stock prices. Because, as I understand, your answer gives a vector with just the history of getting to that 1000th value. So, basically I need 10000 stock prices after 1000 steps.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by