% Monthly Data
% Construct the coming SCI monthly returns based on previous SCI monthly returns
clc
clear
[NUMERIC,TXT,RAW]=xlsread('\path\IDX_Idxtrdmth.xlsx','Shanghai Composite Index');
[a b]=size(NUMERIC);
for m=1:72
NUMERIC1=NUMERIC(:,7);
NUMERIC2(m,:)=NUMERIC1(randint(1,1,[1 a]));
% We randomly choose a previous SCI monthly return between -1 and 1 to be the coming SCI monthly return.
if NUMERIC1(randint(1,1,[1 a]))<1 & NUMERIC1(randint(1,1,[1 a]))>-1
NUMERIC2(m,:)=NUMERIC1(randint(1,1,[1 a]));
end
NUMERIC3=[NUMERIC1; NUMERIC2];
end
% Find the data which satisfies the two requirements of 'dual reversal' timing strategy model.
for n=185:a
if mean(NUMERIC(n-2:n,7))<0 & NUMERIC(n,9)<nanmean(NUMERIC(:,9))
for k=1:24
ALLRET(n,k)=sum(NUMERIC3(n+1:n+3*k,:));
end
end
end
[c,d]=size(ALLRET);
% Calculate all the discription statistics.
for j=1:1:d
Neg(:,j)=length(find(ALLRET(:,j)<0));
Pos(:,j)=length(find(ALLRET(:,j)>0));
Zero(:,j)=c-Neg(:,j)-Pos(:,j);
Max(:,j)=max(ALLRET(:,j));
Min(:,j)=min(ALLRET(:,j));
Sum(:,j)=sum(ALLRET(:,j));
Mean(:,j)=sum(ALLRET(:,j))/(Pos(:,j)+Neg(:,j));
Std(:,j)=std(ALLRET(:,j));
Sharpe(:,j)=Mean(:,j)/Std(:,j);
Success(:,j)=Pos(:,j)/(Pos(:,j)+Neg(:,j));
end
% Calculate the average SCI monthly return and the monthly maximum loss.
for l=1:24
Monthly(:,l)=Mean(:,l)/(3*l);
Monthloss(:,l)=Min(:,l)/(3*l);
end
% Collect all the results into the table named 'Results'.
Results=[ALLRET;Neg;Pos;Zero;Max;Min;Monthloss;Sum;Mean;Monthly;Std;Sharpe;Success];
% Daily Data (based on 5-day time window)
% Construct the coming SCI daily returns based on previous SCI daily returns.
% Determine the lagged periods of both previous SCI daily return and Baidu Index based on R-square.
clc
clear
[NUMERIC,TXT,RAW]=xlsread('\path\IDX_Idxtrdmth.xlsx','Daily Data');
x1=[];x2=[];Y=[];
[a b]=size(NUMERIC);
for i=1:12
for j=1:12
k=max(i,j);
for n=1:a-k
x1(n,:)=mean(NUMERIC(k-i+1:k+n-1,1));
x2(n,:)=log(mean(NUMERIC(k-j+1:k+n-1,2)))/100;
Y(n,:)=NUMERIC(k+n,2);
end
X=[x1 x2];
stats = regstats(Y,X);
beta=stats.beta';
t=stats.tstat.t';
R2=stats.rsquare;
R20(:,j)=stats.rsquare;
Results0(j,:)=[beta NaN t NaN R2];
end
Results1(i,:)=R20;% R-square
Results(13*i-12:13*i-1,:)=Results0; %beta, t-statistic, R-square
end
% Construct 5-day time window 'dual momentum' timing strategy model.
% The code of 10-day time window 'dual momentum' timing strategy model are the same. Here we just present 5-day model.
clc
clear
% Find the data which satisfies the two requirements of 'dual momentum' timing strategy model.
[NUMERIC,TXT,RAW]=xlsread('\path\IDX_Idxtrdmth.xlsx','Daily Data');
[a b]=size(NUMERIC);
for n=10:a-10
if mean(NUMERIC(n-4:n,1))>0 & NUMERIC(n,3)>nanmean(NUMERIC(:,3))
for k=1:10
ALLRET(n+1,k)=sum(NUMERIC(n+1:n+k,1));
end
end
end
[c,d]=size(ALLRET);
% Calculate all the discription statistics.
for j=1:1:d
Neg(:,j)=length(find(ALLRET(:,j)<0));
Pos(:,j)=length(find(ALLRET(:,j)>0));
Zero(:,j)=c-Neg(:,j)-Pos(:,j);
Max(:,j)=max(ALLRET(:,j));
Min(:,j)=min(ALLRET(:,j));
Sum(:,j)=sum(ALLRET(:,j));
Mean(:,j)=sum(ALLRET(:,j))/(Pos(:,j)+Neg(:,j));
Std(:,j)=std(ALLRET(:,j));
Sharpe(:,j)=Mean(:,j)/Std(:,j);
Success(:,j)=Pos(:,j)/(Pos(:,j)+Neg(:,j));
for i=1:c
Asum(i,j)=sum(ALLRET(1:i,j)); % Calculate accumulative SCI daily returns. (5-day rolling)
end
end
for i=1:10
Max_Recall(1,i)=min(Min(:,1:i)); % Calculate maximum retracement.
end
for l=1:10
Dayly(:,l)=Mean(:,l)/(l);
Dayloss(:,l)=Min(:,l)/(l);
end
% Collect all the results into the table named 'Results'.
Results=[ALLRET;Neg;Pos;Zero;Max;Min;Dayloss;Sum;Mean;Dayly;Std;Sharpe;Success;Max_Recall];
> Blockquote