function v=estvol(H,L,O,C,T) %estimates the historical volatility using a BLUE adjusted for the error in observation. % H,L,O,C are all vectors of the same length. 2*epsilon=bid-ask spread. T=1/252 for daily observations N=length(H); Z=log(H./C).*log(H./O)+log(L./O).*log(L./C); m1=mean(Z); s1=var(Z); m2=mean((log(C./O)).^2); v=m1*(6/7)+m2*(1/7); %This is the approximate BLUE weights 6/7 and 1/7. v=sqrt(v/T); % volatility annualized