function [stdercr,stderrcon,eff]=asian2(r,S0,sig,T,K,k,n)
% returns standard errors and effciency (ratio of variances) for 
%the crude MC and control variates simulation 
% S0=initial price, K=strike price
% sig = sigma, k=number of time increments in interval [0,T]
% r the interest rate parameter. Repeats for a total of n simulations.
%[stdercr,stderrcon,eff]=asian2(0.03,95,0.05,0.3,100,5,10000)
%exp(r*T)*S0/K;

v1=[]; 
v2=[]; 
sc=[]; 
mn=(r-sig^2/2)*T/k;
sd=sig*sqrt(T/k); 
Y=normrnd(mn,sd,k,n);

Y=cumsum(Y,1);
S = S0*exp(Y); 
v1= exp(-r*T)*max(mean(S,1)-K,0);
v2=exp(-r*T)*max(S0*exp(mean(Y))-K,0);
aa=cov(v1,v2);
ac=aa(1,2);
beta=ac/var(v2);

valcr=mean(v1);
m2=mean(v2);


eff=var(v1)/var(v1-beta*v2);
stdercr=sqrt(var(v1)/n);
stderrcon=sqrt(var(v1-beta*v2)/n);
