function [xo,xs]=hedge_digital_option(so,x,r,t,sig) 
% example in which we hedge a digital option using xo units of option and
% xs units of stock-provides a delta-gamma hedge, x=strike for call and digital,
% t=maturity for call...corrected Jan 2005
%[xo,xs]=hedge_digital_option(80:120,100,.05,.25,.3) 
do=blsdelta(so,x,r,t,sig,0) ;
go=blsgamma(so,x,r,t,sig,0) ;
[dd,gd]=digitaldelta(so,x,r,sig);
xo=-gd./go;
xs=do.*gd./go-dd;
plot(so,xs,'k',so,xo,'k:')
legend('units of stock held','units of option held')