📄 qihuo.m
字号:
txt1=['训练样本开始时间:',num2str(kd),';结束时间:',num2str(ld),'。共',num2str(d),'天数据'];
txt2=['样本决定系数(R^2):',num2str(STATS_GP1(1)),';AIC值:',num2str(STATS_GP1(4)),';股票和指数相关系数:',num2str(cor(1,2))];
disp('只考虑指数的差分模型为:'); disp(txt);
fprintf(fid,'%s\n','只考虑指数的差分模型为:',txt);
plot(gp1(2,:),'-+');
hold on
plot(nihez1_GP1,'r.');
legend('股价真实值','拟合股价');
xlabel(txt);
title('只考虑指数的差分模型')
[h_l,h_w]=size(gp1);
h_max=max(gp1(2,:));
h_min=min(gp1(2,:));
l=max(h_l,h_w);
axis([0,l,h_min,h_max*1.1]);
grid on
set(gca,'xtick',0:round(l/10):l);
format long g
str=num2str(gp1(1:round(l/10):l,1));
str(:,1:2)=[];
set(gca,'xticklabel',str)
g_max=max(ylim);
g_min=min(ylim);
text(5,g_min+(g_max-g_min)*0.975,txt1);
text(5,g_min+(g_max-g_min)*0.925,txt2);
hold on
plot(1+d,gp(2,ll+d),'ko','Markersize',20);
plot(1,gp(2,ll),'ko','Markersize',20);
figure
plot(xr1_GP1);
legend('相对误差','相对误差=100*(拟合值-真实值)/真实值');
xlabel(txt);
title('只考虑指数的差分模型')
hold on
plot(1+d,xr_GP1(ll+d),'k.','Markersize',20)
plot(1,xr_GP1(ll),'k.','Markersize',20)
figure
normplot(R_GP1);
legend('误差对于正态分布的Q-Q图');
xlabel(txt);
title('只考虑指数的差分模型')
case 3
gp2=gp(:,lll:end);
nihez2_GP1=nihez_GP1(lll:end);
xr2_GP1=xr_GP1(lll:end);
figure
txt=['P(t)-P(t-1)=',num2str(B_GP1(1)),'*(H(t)-H(t-1))'];
disp('只考虑指数的差分模型为:'); disp(txt);
% fprintf(fid,'%s\n','最优模型为:',txt);
plot(gp2(2,:),'-+');
hold on
plot(nihez2_GP1,'r.');
legend('股价真实值','拟合股价');
xlabel(txt);
title('只考虑指数的差分模型')
txt1=['训练样本开始时间:',num2str(kd),';结束时间:',num2str(ld),'。共',num2str(d),'天数据'];
txt2=['样本决定系数(R^2):',num2str(STATS_GP1(1)),';AIC值:',num2str(STATS_GP1(4)),';股票和指数相关系数:',num2str(cor(1,2))];
[h_l,h_w]=size(gp2);
h_max=max(gp2(2,:));
h_min=min(gp2(2,:));
l=max(h_l,h_w);
axis([0,l,h_min,h_max*1.1]);
grid on
set(gca,'xtick',0:round(l/10):l);
format long g
str=num2str(gp2(1,1:round(l/10):l))';
str(:,1:2)=[];
set(gca,'xticklabel',str)
g_max=max(ylim);
g_min=min(ylim);
text(5,g_min+(g_max-g_min)*0.975,txt1);
text(5,g_min+(g_max-g_min)*0.925,txt2);
figure
plot(xr2_GP1);
legend('相对误差','相对误差=100*(拟合值-真实值)/真实值');
xlabel(txt);
title('只考虑指数的差分模型')
[h_l,h_w]=size(gp);
h_max=max(gp2(2,:));
h_min=min(gp2(2,:));
l=max(h_l,h_w);
axis([0,l,h_min,h_max*1.1]);
grid on
set(gca,'xtick',0:round(l/10):l);
format long g
str=num2str(gp2(1,1:round(l/10):l));
str(:,1:2)=[];
set(gca,'xticklabel',str)
figure
normplot(R_GP1);
legend('误差对于正态分布的Q-Q图');
xlabel(txt);
title('只考虑指数的差分模型')
end
end
M_B=get(handles.radiobutton3,'Value');
C_GP2=get(handles.checkbox1,'Value');
if M_B&C_GP2
%--2.股票指数模型1:P(t)-P(t-1)=a1(H(t)-H(t-1))+a2(Vp(t)*(1-exp(P(t-1)-P(t)))/(1+exp(P(t-1)-P(t)))
[B_GP2,BINT_GP2,R_GP2,RINT_GP2,STATS_GP2]=regress(b_gp(ll+1:ll+d)',[b_zhsh(ll+1:ll+d)',obv1_gp(ll+1:ll+d)'],alpha);
nih=B_GP2'*[b_zhsh',obv1_gp']';
nihez_GP2(1)=gp(2,1);
for i=2:gp_length
nihez_GP2(i)=gp(2,i-1)+nih(i);
end
R_GP2=nihez_GP2-gp(2,:);
%-------计算D。W值
S=0; S1=R_GP2(1)^2;
for i=2:gp_length
S=S+R_GP2(i)*R_GP2(i-1);
S1=S1+R_GP2(i)^2;
end
STATS_GP2(4)=2*(1-S/S1);
%-------计算对数似然值
L=-(gp_length)*(1+log(2*pi)+log(R_GP2*R_GP2'/gp_length))/2;
STATS_GP2(5)=L;
%-------计算AIC值
STATS_GP2(6)=2*(-L+3)/gp_length;
%-------计算SC值
STATS_GP2(7)=2*(-L+3*log(gp_length))/gp_length;
%------------计算相对误差
xr_GP2=100*R_GP2'./gp(2,:)';
xr_min=min(xr_GP2);%最小值
xr_max=max(xr_GP2);%最大值
STATS_GP2(8)=xr_min;
STATS_GP2(9)=xr_max;
nu=mean(gp(2,:));
STATS_GP2(10)=dot(gp(2,:)-nihez_GP2,gp(2,:)-nihez_GP2)/dot(gp(2,:)-nu,gp(2,:)-nu);
switch states(3)
case 0
msgbox(' 请选择数据查看方式')
case 1
figure
txt=['P(t)-P(t-1)=',num2str(B_GP2(1)),'*(H(t)-H(t-1))+',num2str(B_GP2(2)),'*(Vp(t)*hp(t))'];
txt1=['训练样本开始时间:',num2str(zhsh(1,ll+1)),';结束时间:',num2str(zhsh(1,d+ll)),'。共',num2str(d),'天数据'];
txt2=['样本决定系数(R^2):',num2str(STATS_GP2(1)),';AIC值:',num2str(STATS_GP2(4)),';股票和指数相关系数:',num2str(cor(1,2))];
disp('考虑股票成交量的差分模型为:'); disp(txt);
plot(gp(2,:),'-+');
hold on
plot(nihez_GP2,'r.');
legend('股价真实值','拟合股价');
xlabel(txt)
title('考虑股票成交量的差分模型')
[h_l,h_w]=size(gp);
h_max=max(gp(2,:));
h_min=min(gp(2,:));
l=max(h_l,h_w);
axis([0,l,h_min,h_max*1.1]);
grid on
set(gca,'xtick',0:round(l/10):l);
format long g
str=num2str(gp(1,1:round(l/10):l));
str(:,1:2)=[];
set(gca,'xticklabel',str)
g_max=max(ylim);
g_min=min(ylim);
text(10,g_min+(g_max-g_min)*0.975,txt1);
text(10,g_min+(g_max-g_min)*0.925,txt2);
hold on
plot(ll+d,gp(2,ll+d),'ko','Markersize',20);
plot(ll,gp(2,ll),'ko','Markersize',20);
figure
plot(xr_GP2);
legend('相对误差','相对误差=100*(拟合值-真实值)/真实值');
xlabel(txt)
title('考虑股票成交量的差分模型')
hold on
plot(ll+d,xr_GP2(ll+d),'k.','Markersize',20)
plot(ll,xr_GP2(ll),'k.','Markersize',20)
figure
normplot(R_GP2);
legend('误差对于正态分布的Q-Q图');
xlabel(txt)
title('考虑股票成交量的差分模型')
case 2
gp1=gp(:,ll:end);
nihez1_GP2=nihez_GP2(ll:end);
xr1_GP2=xr_GP2(ll:end);
figure
txt=['P(t)-P(t-1)=',num2str(B_GP2(1)),'*(H(t)-H(t-1))+',num2str(B_GP2(2)),'*(Vp(t)*hp(t))'];
txt1=['训练样本开始时间:',num2str(zhsh(1,ll+1)),';结束时间:',num2str(zhsh(1,d+ll)),'。共',num2str(d),'天数据'];
txt2=['样本决定系数(R^2):',num2str(STATS_GP2(1)),';AIC值:',num2str(STATS_GP2(4)),';股票和指数相关系数:',num2str(cor(1,2))];
disp('考虑股票成交量的差分模型为:'); disp(txt);
plot(gp1(2,:),'-+');
hold on
plot(nihez1_GP2,'r.');
legend('股价真实值','拟合股价');
xlabel(txt)
title('考虑股票成交量的差分模型')
[h_l,h_w]=size(gp1);
h_max=max(gp1(2,:));
h_min=min(gp1(2,:));
l=max(h_l,h_w);
axis([0,l,h_min,h_max*1.1]);
grid on
set(gca,'xtick',0:round(l/10):l);
format long g
str=num2str(gp1(1,1:round(l/10):l));
str(:,1:2)=[];
set(gca,'xticklabel',str)
g_max=max(ylim);
g_min=min(ylim);
text(10,g_min+(g_max-g_min)*0.975,txt1);
text(10,g_min+(g_max-g_min)*0.925,txt2);
hold on
plot(1+d,gp(2,ll+d),'ko','Markersize',20);
plot(1,gp(2,ll),'ko','Markersize',20);
figure
plot(xr1_GP2);
legend('相对误差','相对误差=100*(拟合值-真实值)/真实值');
xlabel(txt)
title('考虑股票成交量的差分模型')
hold on
plot(1+d,xr_GP2(ll+d),'k.','Markersize',20)
plot(1,xr_GP2(ll),'k.','Markersize',20)
figure
normplot(R_GP2);
legend('误差对于正态分布的Q-Q图');
xlabel(txt)
title('考虑股票成交量的差分模型')
case 3
gp2=gp(:,lll:end);
nihez2_GP2=nihez_GP2(lll:end);
xr2_GP2=xr_GP2(lll:end);
figure
txt=['P(t)-P(t-1)=',num2str(B_GP2(1)),'*(H(t)-H(t-1))+',num2str(B_GP2(2)),'*(Vp(t)*hp(t))'];
txt1=['训练样本开始时间:',num2str(zhsh(1,ll+1)),';结束时间:',num2str(zhsh(1,d+ll)),'。共',num2str(d),'天数据'];
txt2=['样本决定系数(R^2):',num2str(STATS_GP2(1)),';AIC值:',num2str(STATS_GP2(4)),';股票和指数相关系数:',num2str(cor(1,2))];
disp('考虑股票成交量的差分模型为:'); disp(txt);
plot(gp2(2,:),'-+');
hold on
plot(nihez2_GP2,'r.');
legend('股价真实值','拟合股价');
xlabel(txt)
title('考虑股票成交量的差分模型')
[h_l,h_w]=size(gp2);
h_max=max(gp2(2,:));
h_min=min(gp2(2,:));
l=max(h_l,h_w);
axis([0,l,h_min,h_max*1.1]);
grid on
set(gca,'xtick',0:round(l/10):l);
format long g
str=num2str(gp2(1,1:round(l/10):l));
str(:,1:2)=[];
set(gca,'xticklabel',str)
g_max=max(ylim);
g_min=min(ylim);
text(10,g_min+(g_max-g_min)*0.975,txt1);
text(10,g_min+(g_max-g_min)*0.925,txt2);
figure
plot(xr2_GP2);
legend('相对误差','相对误差=100*(拟合值-真实值)/真实值');
xlabel(txt)
title('考虑股票成交量的差分模型')
[h_l,h_w]=size(gp2);
h_max=max(gp2(2,:));
h_min=min(gp2(2,:));
l=max(h_l,h_w);
axis([0,l,h_min,h_max*1.1]);
grid on
set(gca,'xtick',0:round(l/10):l);
format long g
str=num2str(gp2(1,1:round(l/10):l));
str(:,1:2)=[];
set(gca,'xticklabel',str)
figure
normplot(R_GP2);
legend('误差对于正态分布的Q-Q图');
xlabel(txt)
title('考虑股票成交量的差分模型')
end
end
M_B=get(handles.radiobutton3,'Value');
C_GP3=get(handles.radiobutton2,'Value');
if M_B&C_GP3
%--3.股票指数模型2:P(t)-P(t-1)=a1(H(t)-H(t-1))+a2(Vp(t)*(1-exp(P(t-1)-P(t)))/(1+exp(H(t-1)-H(t)))+a3(Vh(t)*(1-exp(H(t-1)-H(t)))/(1+exp(H(t-1)-H(t)))
[B_GP3,BINT_GP3,R_GP3,RINT_GP3,STATS_GP3]=regress(b_gp(ll+1:ll+d)',[b_zhsh(ll+1:ll+d)',obv1_gp(ll+1:ll+d)',obv1_zhsh(ll+1:ll+d)'],alpha);
nih=B_GP3'*[b_zhsh',obv1_gp',obv1_zhsh']';
nihez_GP3(1)=gp(2,1);
for i=2:gp_length
nihez_GP3(i)=gp(2,i-1)+nih(i);
end
R_GP3=nihez_GP3-gp(2,:);
%-------计算D。W值
S=0; S1=R_GP3(1)^2;
for i=2:gp_length
S=S+R_GP3(i)*R_GP3(i-1);
S1=S1+R_GP3(i)^2;
end
STATS_GP3(4)=2*(1-S/S1);
%-------计算对数似然值
L=-(gp_length)*(1+log(2*pi)+log(R_GP3*R_GP3'/gp_length))/2;
STATS_GP3(5)=L;
%-------计算AIC值
STATS_GP3(6)=2*(-L+3)/gp_length;
%-------计算SC值
STATS_GP3(7)=2*(-L+3*log(gp_length))/gp_length;
%------------计算相对误差
xr_GP3=100*R_GP3'./gp(2,:)';
xr_min=min(xr_GP3);%最小值
xr_max=max(xr_GP3);%最大值
STATS_GP3(8)=xr_min;
STATS_GP3(9)=xr_max;
nu=mean(gp(2,:));
STATS_GP3(10)=dot(gp(2,:)-nihez_GP3,gp(2,:)-nihez_GP3)/dot(gp(2,:)-nu,gp(2,:)-nu);
switch states(3)
case 0
msgbox(' 请选择数据查看方式')
case 1
figure
txt=['P(t)-P(t-1)=',num2str(B_GP3(1)),'*(H(t)-H(t-1))+',num2str(B_GP3(2)),'*(Vp(t)*hp(t)+',num2str(B_GP3(3)),'*(VH(t)*hH(t))'];
txt1=['训练样本开始时间:',num2str(kd),';结束时间:',num2str(ld),'。共',num2str(d),'天数据'];
txt2=['样本决定系数(R^2):',num2str(STATS_GP3(1)),';AIC值:',num2str(STATS_GP3(4)) ,';股票和指数相关系数:',num2str(cor(1,2))];
disp('考虑成交量的差分模型为:'); disp(txt);
plot(gp(2,:),'-+');
hold on
plot(nihez_GP3,'r.');
legend('股价真实值','拟合股价');
title('考虑成交量的差分模型')
xlabel(txt)
[h_l,h_w]=size(gp);
h_max=max(gp(2,:));
h_min=min(gp(2,:));
l=max(h_l,h_w);
axis([0,l,h_min,h_max*1.1]);
grid on
set(gca,'xtick',0:round(l/10):l);
format long g
str=num2str(gp(1,1:round(l/10):l));
str(:,1:2)=[];
set(gca,'xticklabel',str)
g_max=max(ylim);
g_min=min(ylim);
text(5,g_min+(g_max-g_min)*0.975,txt1);
text(5,g_min+(g_max-g_min)*0.925,txt2);
hold on
plot(ll+d,gp(2,ll+d),'ko','Markersize',20);
plot(ll,gp(2,ll),'ko','Markersize',20);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -