- Joined
- 6/20/11
- Messages
- 25
- Points
- 11
Hi all,
I try to understand this mathlab code for simulating a brownian motion. I understand that we generate a matrix of (n, m) random normal values, then we use the function cumsum to obtain a matrix of (1, m) : m scenarios.
But why do we use the zeros (1, m) matrix ? and why are they talking about n+1 observations in the commentary ?
function prices = SimBS1d( m, n, mu, sigma, h, s0)
% This function generates m different paths of a Geometric Brownian motion
% with n+1 observations with parameters mu and sigma, and initial value s0.
% Time between observations: h
%
% Inputs: m, n, mu, sigma, h, s0
% Outputs: simulated series and graph
%
% simulated prices
prices = s0 * exp( [zeros(1, m); cumsum( ( mu - 0.5 * sigma^2 ) * h + sigma * sqrt( h ) * randn( n, m ) )] );
% graph...
I try to understand this mathlab code for simulating a brownian motion. I understand that we generate a matrix of (n, m) random normal values, then we use the function cumsum to obtain a matrix of (1, m) : m scenarios.
But why do we use the zeros (1, m) matrix ? and why are they talking about n+1 observations in the commentary ?
function prices = SimBS1d( m, n, mu, sigma, h, s0)
% This function generates m different paths of a Geometric Brownian motion
% with n+1 observations with parameters mu and sigma, and initial value s0.
% Time between observations: h
%
% Inputs: m, n, mu, sigma, h, s0
% Outputs: simulated series and graph
%
% simulated prices
prices = s0 * exp( [zeros(1, m); cumsum( ( mu - 0.5 * sigma^2 ) * h + sigma * sqrt( h ) * randn( n, m ) )] );
% graph...