Simple simulation of stock price

2 visualizzazioni (ultimi 30 giorni)
N/A
N/A il 18 Ago 2017
Commentato: N/A il 18 Ago 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 Commento
Image Analyst
Image Analyst il 18 Ago 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.

Accedi per commentare.

Risposte (1)

Kuifeng
Kuifeng il 18 Ago 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 Commento
N/A
N/A il 18 Ago 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.

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by