function VG() % A stochastic process S(t) is said to follow a GBM if it satisfies the Stochastic Differential Equation: dS(t)=mu*S(t)*dt+sigma*S(t)*dW(t) % This SDE has the analytic solution S(t)=S(0)*exp((mu-(sigma^2)/2)*t+sigma*W(t)) with E(S(t))=S(0)*exp(mu*t) % However, I propose that S(0) be replaced with S(t-1) t=1; T=390; sigma=0.05; mu(1)=0; S(1)=4; for t=1:T % t must have increments of length 1 for randn function to be appropriate S(t+1)=S(t).*exp(mu.*t+sigma.*unifSample([0.15 0.7 0.15],[-0.1 0 0.1])); end plot([1:T+1],S) axis([0 T+1 3 5]) grid on