How can i simulate N trajectories of a Geometric Brownian motion with an initial condition
Show older comments
Hi,
I'm a new user of Matlab. i have to simulate N trajectories of a Geometric Brownian motion with initial condition S1Begin > S1(optimal). S1Begin is the initial value, and S1optimal is the trigger value for undertaking investment. they are both input data.
my code is:
function [S, t] = geom_brownian( sigma, T, S1Begin, drift, dt, nb_traj)
% Geomteric Brownian Motion
% uso:
% S = geom_brownian( sigma, T, S0, mu, step)
% esempio:
% [S, t] = geom_brownian( .12, 5, 50, 100, .05, 1/255);
nT = ceil(T/dt); % numero di passi = T/step
W = sigma * sqrt(dt) * cumsum(randn(nT,nb_traj)); % W_k = sigma*sqrt(step)*(U_k + ... + U_0)
c = repmat((drift - sigma^2/2) *dt * (1:nT)',1,nb_traj);
S = [repmat(S1Begin,1,nb_traj); S1Begin * exp( c + W)]; %S = [repmat(S0,1,nb_traj); S0 * exp( c + W)];
if nargout > 1
t = [0;dt * (1:nT)'];
end
and i don't know where to insert such a condition.
Thxx
Answers (0)
Categories
Find more on Get Started with MATLAB 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!