%This code calculate multihorizon hedge ratio based on basis regression
%model
clear all; clc;
tic;
data=load('data.txt');%%Here, we need to download the original price data
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,:)=BRratio(spot(i:i+windowlength),futures(i:i+windowlength));
end
ratio=hedgeratio(1:samplelength-windowlength-h);
toc;