%x=load('x.txt');
%y=load('y.txt');
%data=[x y];
clear all; clc;
tic;
data=load('data.txt')/100;
p=1;
q=1;
windowlength=250;
for i=1:size(data,1)-windowlength
%    for i=1:1000   %574
fore(:,:,i)=scalarfore(data(i:i+windowlength-1,:),p,q)*10000;
    end
    for i=1:size(data,1)-windowlength
    hta(i)=fore(1,1,i);
    htb(i)=fore(2,2,i);
    htab(i)=fore(1,2,i);
    end
    hta=hta';
    htb=htb';
    htab=htab';
    ratio=htab./htb;
hedgereturn=data(501:1500,1)-ratio.*data(501:1500,2);
naivereturn=data(501:1500,1)-data(501:1500,2);
varmodel=var(hedgereturn);
varnaive=var(naivereturn);
modelvol=hedgereturn.^2;
naivevol=naivereturn.^2;
hedgereturn=hedgereturn*100;
toc;
    