plotting multiple brownian motions curves on the same plot
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Jan
am 21 Mär. 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.
Antworten (1)
Naman Bhaia
am 1 Mär. 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. 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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Directed Graphs finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!