plotting multiple brownian motions curves on the same plot

8 ビュー (過去 30 日間)
Katie Brewer
Katie Brewer 2019 年 2 月 26 日
コメント済み: Rena Berman 2019 年 4 月 2 日
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.
Rena Berman
Rena Berman 2019 年 4 月 2 日
(Answers Dev) Restored edit

サインインしてコメントする。

回答 (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 Center および File Exchange2-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