function [h,l,o,c]=bootstrp1(H,L,O,C,date,d1,d2)
%apply to logarithm of data. It must be adjusted so that increments are symmetric about 0.
% the problem with this function is it assumes that the exponential rv and the increments are iid.
% renamed to avoid the built-in function bootstrp
w=(date>d1)&(date<d2);
H=log(H(w));
L=log(L(w));
O=log(O(w));
C=log(C(w));
%Z1=(H-O).*(H-C);
%Z2=(L-O).*(L-C);
[U,V]=unf(H,L,O,C);
%plot(trim(Z1,.05),trim(Z2,.05),'.')
%title(' Joint distribution of "exponential statistic" for max, min')
%xlabel('Z for high')
%ylabel('Z for low')
plot(U,V,'.')
title(' Joint distribution of Uniform statistic" for high,low')
xlabel('U for high')
ylabel('U for low')
%figure
%hist(trim(Z1, .05),30)
%figure
%hist(trim(Z2, .05),30)
%corrcoef(Z1,Z2)
%figure
%hist(U, 25)
%figure
%hist(V, 25)
n=length(H);
%r= median(diff(C));
day=C-O;
md=median(day);
C=C-md;
%day=day-md;
night=O(2:n)-C(1:(n-1));
mn=median(night);
%night=night-mn;
d=day(floor(1+n*rand(1,n)));
n1=night(floor(1+(n-1)*rand(1,n-1)));
i3=floor(1+n*rand(1,n));
o=O(1)+cumsum([0 ; d(1:n-1)+n1]);
c=o+d;
u=Z1(i3);
v=Z2(i3);
h=.5*(o+c+sqrt((o-c).^2 + 4*Z1));
l=.5*(o+c-sqrt((o-c).^2 + 4*Z2));
h=exp(h);
l=exp(l);
o=exp(o);
c=exp(c);
figure
%plot(date(w),o,'y')
hold on
%plot(date(w),c,'g')
plot(date(w),h,'r')
plot(date(w),l,'b')


