function [St,t]=simulateBS(S,r,T,sigma,n)
% n is the number if increments  for interval (0,T) 
% outputs time t and stock price St. 
% to value an option strike 1425 run as follows:
%ST=[];  for i=1:1000 ; S=simulateBS(1432.25,.03,7/252,.195,6);ST=[ST S(7)]; end; mean(exp(-.03*7/252)*max((ST-1425),0))
% for  a more efficient version  of the same thing generating ony the final value from the lognormal 
% use r=.03;sigma=.195;T=7/252;ST=1432.25*exp(normrnd((r-.5*sigma^2)*T,sigma*sqrt(T),1,100000)); mean(exp(-.03*7/252)*max((ST-1425),0))
%
St=S;
h=T/n ;
for i=1:n
   Z=normrnd(r*S*h,sigma*S*sqrt(h));
   S=S+normrnd(r*S*h,sigma*S*sqrt(h));
   St=[St S];
end
t=0:h:T;

   
   
