function [eff,m,v]=importance2(S0,r,K,sigma,T)
% simple importance sampling estimator of call option price-- outputs efficiency relative to crude.
% [eff,m,v]=importance2(10,.02,15,.2,.25)
Z=randn(1,1000000);
%first do crude
ZT=(r-.5*sigma^2)*T+sigma*sqrt(T).*Z;
est1=exp(-r*T)*max(0,S0*exp(ZT)-K);
% now do importance
ZT=(log(K/S0)-.5*sigma^2)*T+sigma*sqrt(T).*Z;
ST=S0*exp(ZT);
est2=exp(-r*T)*max(0,ST-K).*normpdf(ZT,(r-.5*sigma^2)*T,sigma*sqrt(T))./normpdf(ZT,(log(K/S0)-.5*sigma^2)*T,sigma*sqrt(T));
v=[var(est1) var(est2)];
m=[mean(est1) mean(est2)];
eff=v(1)/v(2);



