function [est,v,n]=stratified(x,nsample)
est=0;
n=[];
m=length(x);
for i=1:m-1    %preliminary simulation to optimize sample size
   v= var(callopt2(unifrnd(x(i),x(i+1),1,10000),10,10,.05,.2,.25));
   n=[n (x(i+1)-x(i))*sqrt(v)];
end
n=floor(nsample*n/sum(n));
v=0;
for i=1:m-1
   F=callopt2(unifrnd(x(i),x(i+1),1,n(i)),10,10,.05,.2,.25);
   est=est+(x(i+1)-x(i))*mean(F);
   v=v+var(F)*(x(i+1)-x(i))^2/n(i);
   end


      