plotting multiple brownian motions curves on the same plot
이전 댓글 표시
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
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.
Rena Berman
2019년 4월 2일
(Answers Dev) Restored edit
답변 (1개)
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. Place the “plot” command inside the for loop
- 2. Before the for loop use “hold on” command
- 3. After the for loop use the “hold off” command
Consider the following example
hold on
for i=1:101
j=i;
plot(i,j,'x');
end
hold off

카테고리
도움말 센터 및 File 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!