function [est,v,m,stderr,eff]=stratif1(r,S0,sig,T,K,R,nsample,m)
% function returns:
% est which is the stratified estimate of price (asian call option)
% v is standars deviation of est
% m is the crude MC estimate
%stderr is the standard error of crude MC estimate
%eff is the efficiency
%The input parameters are:
%r is the interest rate
%S0 is the initial stock price
%sig is the stock volatility
%T is time to maturity
%K is strike
%R is the number of price averaging times
%nsample is the the number of prices we  simulate
%m is the number of strata
est=0;
n=[];
%use e.g. [valstrat,stderrstrat,valcrude,stderrcrude,efficiency]=stratif2(0.03,90,0.3,0.9,100,5,10000,100)

a=0;
b=1/m;
n=floor(nsample/m);  
v=0;
for i=1:m
 
F=asianvaluestr(a,b,r,S0,sig,T,K,R,n); %evaluate the function
%f at n(i) uniform points in interval (0,1)
est=est+(b-a)*mean(F);
v=v+var(F)*(b-a)^2/n;
a=b;b=b+1/m;
end
%v=sqrt(v);
[m,stderr]=asiancrude(r,S0,sig,T,K,R,nsample);
eff=stderr/v;
v=sqrt(v);
stderr=sqrt(stderr);
