% Price a down and out put option on an asset obeying 
%   d S = r S dt + sqrt( b0 + b1 S^2) dW 

S0 = 1;
K = 1.1; 
r = 0.03;
b0 = 0.01; 
b1 = 0.04;
T = 1; 
B = 0.8;

N = 200; 
h = T/N; 
M = 50000;
S = S0 * ones(M,N+1);
Z = randn(M,N);

for i=1:N
    S(:,i+1) = S(:,i) + S(:,i)*r*h + sqrt(h)*sqrt(b0+b1*S(:,i).^2).*Z(:,i);
end

P = K - S(:,N+1) ; 
Q = min(S, [], 2); 
V = exp(-r*T)*P.*(P>0).*(Q>B) ; 
[mean(V), std(V)/sqrt(M)]