plotting multiple brownian motions curves on the same plot

8 views (last 30 days)
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 Comments
Jan
Jan on 21 Mar 2019
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.

Sign in to comment.

Answers (1)

Naman Bhaia
Naman Bhaia on 1 Mar 2019
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

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!