N=100;
h=1/N;
M=10000;
Z=randn(M,N);
S=ones(M,N+1);

for i=1:N
    S(:,i+1)=S(:,i).*exp(0.1*h+0.5*sqrt(h)*Z(:,i));
end

B=1.5:0.05:2.5;
ans=zeros(size(B));

for j=1:length(B) 
    test=(S(:,N+1)>=1).*(max(S,[],2)<=B(j));
    ret=exp(-0.1)*(S(:,N+1).*(test==1) + (test==0));
    ans(j)=mean(ret);
end

plot(B,ans,'r',B,ones(size(B)),'b')
xlabel('B')