function [v,ss0,sr,ssigma]=simdigital(u,S0,ex,r,sigma,T)
% simulates value of a digital option
x=norminv(u,log(S0)+r*T-sigma^2*T/2,sigma*sqrt(T)); % log of stock price
z=(x-log(S0)-r*T+sigma^2*T/2)/(sigma*sqrt(T));   % x standardized
v=exp(-r*T)*(x>log(ex));          %value of digital option
ss0=z/(S0*sigma*sqrt(T));       % score for estimating S0
sr=z*sqrt(T)/sigma;              % score for estimating r
ssigma=-z*sqrt(T)+(z.^2-1)/sigma;   % score for estimating sigma