function r=ECgivenL(sig)
% plots the values of E(C|L>=l) where l=Oexp(=a), sig=volatility parameter,
% mu=drift. 
O=40; l=30; a=log(O/l); Exp_return=1.08; % return in percentage
mu=log(Exp_return)-.5*sig.^2;
n=length(sig); a=a*ones(1,n); 
lam=2*a./(sig.^2);
d2=[(a+mu)./sig;(mu-a)./sig];
d1=d2+[sig;sig];
num=exp(mu+.5*sig.^2).*normcdf(d1(1,:),0,1)-exp((-lam).*(mu+a)+(1-lam).*mu+.5*(1-lam).^2.*sig.^2).*normcdf(d1(2,:),0,1);
den=normcdf(d2(1,:),0,1)-exp((-lam).*(mu+a)+.5*lam.^2.*sig.^2).*normcdf(d2(2,:),0,1);
r=O*num./den;
plot(sig,r)
grid on
xlabel('\sigma')
ylabel('E[C|L \geq 30]')