%This code is used to calculate multihorizon hedge based on VEC model
clear all; clc;
data=load('data.txt');%%Here, we need to load the original price data
tic;
spot=data(:,1);
futures=data(:,2);
samplelength=size(spot,1);
for i=2:samplelength
    spotret(i-1,:)=100*(log(spot(i))-log(spot(i-1)));
    futuresret(i-1,:)=100*(log(futures(i))-log(futures(i-1)));
end
windowlength=500;
h=1;  %%%h=horizon
for i=1:samplelength-windowlength-1
    hedgeratio(i,:)=VECratio(spot(i:i+windowlength),futures(i:i+windowlength));
end
ratio=hedgeratio(1:samplelength-windowlength-h);
toc;