
function ratio=VECratioR(spot,futures)
length=size(spot,1);
%First, construct vector error correction term
beta0=regress(log(spot), [ones(length,1) log(futures)]);
z=log(spot)-[ones(length,1) log(futures)]*beta0;
z=z(2:end);
%Second, construct the return series
for i=2:length
    spotret(i-1,:)=log(spot(i))-log(spot(i-1));
    futuresret(i-1,:)=log(futures(i))-log(futures(i-1));
end
%Second, estimate the ohr
retlen=size(spotret,1);
beta1=regress(spotret(2:end),[ones(retlen-1,1) spotret(1:end-1) futuresret(1:end-1) z(1:end-1)]);
beta2=regress(futuresret(2:end),[ones(retlen-1,1) spotret(1:end-1) futuresret(1:end-1) z(1:end-1)]);
resid1=spotret(2:end)-[ones(retlen-1,1) spotret(1:end-1) futuresret(1:end-1) z(1:end-1)]*beta1;
resid2=futuresret(2:end)-[ones(retlen-1,1) spotret(1:end-1) futuresret(1:end-1) z(1:end-1)]*beta2;
ratio=cov(resid1,resid2)/var(resid2);
ratio=ratio(1,2);
