plotting multiple brownian motions curves on the same plot

8 次查看(过去 30 天)
I have the following code to create the random path of a geometic brownian motion but I want to plot every iteration on top of eachother to look like the following
I have read all online sources from matlab and watch youtube videos to try and help but nothing I do works.
%Generates the path of the underlying for a monte carlo simulated stock
%http://ac.aua.am/tigran_bunarjyan/Public/NA_Monte%20Carlo%20Presentation.pdf
clear all
clc
S=100;
sigma=0.3;
T=1;
r=0.05;
step=1000;
dt=T/step;
sqdt=sqrt(dt);
rr=randn(1, step);
St=S;
stockPrices=[];
ts=[];
stockPrices(1)=S;
ts(1)=0;
for st=1:step
St=St*(1+r*dt+sigma*sqdt*rr(1,st));
stockPrices(st+1)=St;
ts(st+1)=st;
end
plot(ts,stockPrices)
title("Stock Price for Day =0...500");
xlabel=("Day");
ylabel=("Price");
  2 个评论
Jan
Jan 2019-3-21
Katie Brewer has removed the contents of all of her questions. It seems, like she is not interested in a cooperative usage of the forum. What a pity.

请先登录,再进行评论。

回答(1 个)

Naman Bhaia
Naman Bhaia 2019-3-1
Hey Katie,
According to my understanding you are generating only one plot. If you want to plot a graph for each iteration of the for loop do the following
  1. 1. Place the “plot” command inside the for loop
  2. 2. Before the for loop use “hold on” command
  3. 3. After the for loop use the “hold off” command
For more clarification on hold command you can refer to this link.
Consider the following example
hold on
for i=1:101
j=i;
plot(i,j,'x');
end
hold off
case.PNG

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by