%read the data
clear all
load DS_EXCESS_RETURNS.txt
load EH_EXCESS_RETURNS.txt
load EM_EXCESS_RETURNS.txt
load FIA_EXCESS_RETURNS.txt
load M_EXCESS_RETURNS.txt
load MA_EXCESS_RETURNS.txt

data=[EM_EXCESS_RETURNS EH_EXCESS_RETURNS M_EXCESS_RETURNS DS_EXCESS_RETURNS FIA_EXCESS_RETURNS MA_EXCESS_RETURNS];
[T,k]=size(data)

figure(1)
subplot(2,3,1)
normplot(data(:,1))
xlabel('HFR-EM')
subplot(2,3,2)
normplot(data(:,2))
xlabel('HFR-EH');
subplot(2,3,3)
normplot(data(:,3))
xlabel('HFR-M');
subplot(2,3,4)
normplot(data(:,4))
xlabel('HFR-DS');
subplot(2,3,5)
normplot(data(:,5))
xlabel('HFR-FIA');
subplot(2,3,6)
normplot(data(:,6))
xlabel('HFR-MA');

figure(2)
subplot(2,3,1)
qqplot(data(:,1))
xlabel('HFR-EM')
subplot(2,3,2)
qqplot(data(:,2))
xlabel('HFR-EH');
subplot(2,3,3)
qqplot(data(:,3))
xlabel('HFR-M');
subplot(2,3,4)
qqplot(data(:,4))
xlabel('HFR-DS');
subplot(2,3,5)
qqplot(data(:,5))
xlabel('HFR-FIA');
subplot(2,3,6)
qqplot(data(:,6))
xlabel('HFR-MA');

figure(3)
subplot(2,3,1)
plot(data(:,1))
title('HFR-EM');
ylabel(' ')
set(gca,'XTick',6:24:143)
set(gca,'XTickLabel',{'1994','1996','1998','2000','2002','2004'})
subplot(2,3,2)
plot(data(:,2))
title('HFR-EH');
ylabel(' ')
set(gca,'XTick',6:24:143)
set(gca,'XTickLabel',{'1994','1996','1998','2000','2002','2004'})
subplot(2,3,3)
plot(data(:,3))
title('HFR-M');
ylabel(' ')
set(gca,'XTick',6:24:143)
set(gca,'XTickLabel',{'1994','1996','1998','2000','2002','2004'})
subplot(2,3,4)
plot(data(:,4))
title('HFR-DS');
ylabel(' ')
set(gca,'XTick',6:24:143)
set(gca,'XTickLabel',{'1994','1996','1998','2000','2002','2004'})
subplot(2,3,5)
plot(data(:,5))
title('HFR-FIA');
ylabel(' ')
set(gca,'XTick',6:24:143)
set(gca,'XTickLabel',{'1994','1996','1998','2000','2002','2004'})
subplot(2,3,6)
plot(data(:,6))
title('HFR-MA');
ylabel(' ')
set(gca,'XTick',6:24:143)
set(gca,'XTickLabel',{'1994','1996','1998','2000','2002','2004'})


mesos=mean(data)';
stdev=std(data)';
medianm=median(data)';
asymetry=skewness(data)';
kurtosi=kurtosis(data)';
minim=min(data)';
maxim=max(data)';

[mesos stdev medianm asymetry kurtosi minim maxim]

%     0.0058    0.0420    0.0115   -0.9337    7.6704   -0.2143    0.1437
%     0.0083    0.0258    0.0091    0.2434    4.8028   -0.0806    0.1045
%     0.0050    0.0210    0.0043    0.0202    3.8519   -0.0669    0.0639
%     0.0065    0.0159    0.0076   -1.5155   11.3114   -0.0891    0.0468
%     0.0017    0.0113    0.0031   -3.1233   19.4060   -0.0681    0.0257
%     0.0045    0.0101    0.0061   -2.4285   14.7142   -0.0610    0.0200
    

absdata=abs(data);
sqrdata=data.^2;
%calculate Ljung-Box statistic
H=[]; P=[]; Qstat=[]; CV=[];
for i=1:k
    [H(i),P(i),Qstat(i),CV(i)]=lbqtest(data(:,i),12);
end
[H' P' Qstat' CV']

%          0    0.0571   20.5656   21.0261
%          0    0.2323   15.1690   21.0261
%          0    0.6998    9.0362   21.0261
%     1.0000    0.0019   31.0513   21.0261
%     1.0000    0.0022   30.7386   21.0261
%          0    0.3448   13.3399   21.0261

%calculate Ljung-Box statistic of absolute returns
Habs=[]; Pabs=[]; Qstatabs=[]; CVabs=[];
for i=1:k
    [Habs(i),Pabs(i),Qstatabs(i),CVabs(i)]=lbqtest(absdata(:,i),12);
end
[Habs' Pabs' Qstatabs' CVabs']

%          0    0.1007   18.5217   21.0261
%     1.0000    0.0006   34.3762   21.0261
%          0    0.8114    7.6554   21.0261
%          0    0.1765   16.3311   21.0261
%     1.0000    0.0000   43.8733   21.0261
%          0    0.6240    9.9087   21.0261

%calculate Ljung-Box statistic of squared returns
Hsqr=[]; Psqr=[]; Qstatsqr=[]; CVsqr=[];
for i=1:k
    [Hsqr(i),Psqr(i),Qstatsqr(i),CVsqr(i)]=lbqtest(sqrdata(:,i),12);
end
[Hsqr' Psqr' Qstatsqr' CVsqr']

%          0    0.3350   13.4826   21.0261
%     1.0000    0.0003   36.2067   21.0261
%          0    0.8882    6.5111   21.0261
%          0    0.6941    9.1030   21.0261
%     1.0000    0.0000   41.1755   21.0261
%          0    0.9966    2.8339   21.0261

figure(4)
subplot(2,3,1)
autocorr(absdata(:,1),12)
title('abs-HFR-EM')
subplot(2,3,2)
autocorr(absdata(:,2),12)
title('abs-HFR-EH')
subplot(2,3,3)
autocorr(absdata(:,3),12)
title('abs-HFR-M')
subplot(2,3,4)
autocorr(absdata(:,4),12)
title('abs-HFR-DS')
subplot(2,3,5)
autocorr(absdata(:,5),12)
title('abs-HFR-FIA')
subplot(2,3,6)
autocorr(absdata(:,6),12)
title('abs-HFR-MA')

figure(5)
subplot(2,3,1)
autocorr(sqrdata(:,1),12)
title('sqr-HFR-EM')
subplot(2,3,2)
autocorr(sqrdata(:,2),12)
title('sqr-HFR-EH')
subplot(2,3,3)
autocorr(sqrdata(:,3),12)
title('sqr-HFR-M')
subplot(2,3,4)
autocorr(sqrdata(:,4),12)
title('sqr-HFR-DS')
subplot(2,3,5)
autocorr(sqrdata(:,5),12)
title('sqr-HFR-FIA')
subplot(2,3,6)
autocorr(sqrdata(:,6),12)
title('sqr-HFR-MA')

