⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qihuo.m

📁 对金融数据(股票
💻 M
📖 第 1 页 / 共 5 页
字号:
         figure
plot(xr_GP3);
   legend('相对误差','相对误差=100*(拟合值-真实值)/真实值');;
title('考虑成交量的差分模型')
       xlabel(txt)
       hold on 
         plot(ll+d,xr_GP3(ll+d),'k.','Markersize',20)
         plot(ll,xr_GP3(ll),'k.','Markersize',20)
       

figure
normplot(R_GP3);
legend('误差对于正态分布的Q-Q图');
title('考虑成交量的差分模型')
       xlabel(txt)

     case 2
           gp1=gp(:,ll:end);
          nihez1_GP3=nihez_GP3(ll:end);
          xr1_GP3=xr_GP3(ll:end);
         
          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(gp1(2,:),'-+');
          hold on
        plot(nihez1_GP3,'r.');
          legend('股价真实值','拟合股价');
        title('考虑成交量的差分模型')
       xlabel(txt)
       [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(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_GP3);
   legend('相对误差','相对误差=100*(拟合值-真实值)/真实值');;
title('考虑成交量的差分模型')
       xlabel(txt)
       hold on 
         plot(1+d,xr_GP3(ll+d),'k.','Markersize',20)
         plot(1,xr_GP3(ll),'k.','Markersize',20)
       

figure
normplot(R_GP3);
legend('误差对于正态分布的Q-Q图');
title('考虑成交量的差分模型')
       xlabel(txt)

      case 3      
         gp2=gp(:,lll:end);
          nihez2_GP3=nihez_GP3(lll:end);
          xr2_GP3=xr_GP3(lll:end);
           
 
    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))'];
        

disp('考虑成交量的差分模型为:'); disp(txt);
          plot(gp2(2,:),'-+');
          hold on
        plot(nihez2_GP3,'r.');
          legend('股价真实值','拟合股价');
        title('考虑成交量的差分模型')
       xlabel(txt)
       txt1=['训练样本开始时间:',num2str(kd),';结束时间:',num2str(ld),'。共',num2str(d),'天数据'];
txt2=['样本决定系数(R^2):',num2str(STATS_GP3(1)),';AIC值:',num2str(STATS_GP3(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_GP3);
   legend('相对误差','相对误差=100*(拟合值-真实值)/真实值');;
title('考虑成交量的差分模型')
       xlabel(txt)
      [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_GP3);
legend('误差对于正态分布的Q-Q图');
title('考虑成交量的差分模型')
       xlabel(txt)
end
end
M_SHY=get(handles.radiobutton4,'Value');
C_GP1=get(handles.radiobutton1,'Value');
if M_SHY&C_GP1
%--4.收益率-指数模型1:(P(t)-P(t-1))/P(t-1)=a1(H(t)-H(t-1))/H(t-1)
[B_SHY1,BINT_SHY1,R_SHY1,RINT_SHY1,STATS_SHY1]=regress(shy_gp(ll+1:ll+d)',shy_zhsh(ll+1:ll+d)',alpha);
nih=B_SHY1'*shy_zhsh;
       nihez_SHY1(1)=gp(2,1);
       for i=2:gp_length 
          nihez_SHY1(i)=gp(2,i-1)*(1+nih(i));
       end
        R_SHY1=nihez_SHY1-gp(2,:);

%-------计算D。W值
S=0; S1=R_SHY1(1)^2;
for i=2:gp_length
    S=S+R_SHY1(i)*R_SHY1(i-1);
    S1=S1+R_SHY1(i)^2;
end
STATS_SHY1(4)=2*(1-S/S1);
%-------计算对数似然值
L=-(gp_length)*(1+log(2*pi)+log(R_SHY1*R_SHY1'/gp_length))/2;
STATS_SHY1(5)=L;
%-------计算AIC值
STATS_SHY1(6)=2*(-L+2)/gp_length;
%-------计算SC值
STATS_SHY1(7)=2*(-L+2*log(gp_length))/gp_length;
%------------计算相对误差
xr_SHY1=100*R_SHY1'./gp(2,:)';
xr_min=min(xr_SHY1);%最小值
xr_max=max(xr_SHY1);%最大值

STATS_SHY1(8)=xr_min;
STATS_SHY1(9)=xr_max;

nu=mean(gp(2,:));
STATS_SHY1(10)=dot(gp(2,:)-nihez_SHY1,gp(2,:)-nihez_SHY1)/dot(gp(2,:)-nu,gp(2,:)-nu);

 switch states(3)
    case 0
        msgbox(' 请选择数据查看方式')
    case 1
        figure
        txt=['(P(t)-P(t-1))/P(t-1)=',num2str(B_SHY1(1)),'*(H(t)-H(t-1))/H(t-1)'];
        txt1=['训练样本开始时间:',num2str(kd),';结束时间:',num2str(ld),'。共',num2str(d),'天数据'];
        txt2=['样本决定系数(R^2):',num2str(STATS_SHY1(1)),';AIC值:',num2str(STATS_SHY1(4)) ,';股票和指数相关系数:',num2str(cor(1,2))];
          disp('只考虑指数的收益率模型为:'); disp(txt);
          plot(gp(2,:),'-+');
          hold on
        plot(nihez_SHY1,'r.');
          legend('股价真实值','拟合股价');
       title('只考虑指数的收益率模型')
       xlabel(txt)
        
       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);
                
plot(gp(2,:),'-+');
hold on
plot(nihez_SHY1,'r.');
legend('股价真实值','拟合股价');

figure
plot(xr_SHY1);
   legend('相对误差','相对误差=100*(拟合值-真实值)/真实值');;
 hold on 
         plot(ll+d,xr_SHY1(ll+d),'k.','Markersize',20)
         plot(ll,xr_SHY1(ll),'k.','Markersize',20)
      title('只考虑指数的收益率模型')
       xlabel(txt)
figure
normplot(R_SHY1);
legend('误差对于正态分布的Q-Q图');
title('只考虑指数的收益率模型')
       xlabel(txt)
       

    case 2
          gp1=gp(:,ll:end);
          nihez1_SHY1=nihez_SHY1(ll:end);
          xr1_SHY1=xr_SHY1(ll:end);
          
          figure
        txt=['(P(t)-P(t-1))/P(t-1)=',num2str(B_SHY1(1)),'*(H(t)-H(t-1))/H(t-1)'];
        txt1=['训练样本开始时间:',num2str(kd),';结束时间:',num2str(ld),'。共',num2str(d),'天数据'];
        txt2=['样本决定系数(R^2):',num2str(STATS_SHY1(1)),';AIC值:',num2str(STATS_SHY1(4)) ,';股票和指数相关系数:',num2str(cor(1,2))];
          disp('只考虑指数的收益率模型为:'); disp(txt);
          plot(gp1(2,:),'-+');
          hold on
        plot(nihez1_SHY1,'r.');
          legend('股价真实值','拟合股价');
       title('只考虑指数的收益率模型')
       xlabel(txt)
        
       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);
                
plot(gp1(2,:),'-+');
hold on
plot(nihez1_SHY1,'r.');
legend('股价真实值','拟合股价');

figure
plot(xr1_SHY1);
   legend('相对误差','相对误差=100*(拟合值-真实值)/真实值');;
 hold on 
         plot(1+d,xr_SHY1(ll+d),'k.','Markersize',20)
         plot(1,xr_SHY1(ll),'k.','Markersize',20)
      title('只考虑指数的收益率模型')
       xlabel(txt)
figure
normplot(R_SHY1);
legend('误差对于正态分布的Q-Q图');
title('只考虑指数的收益率模型')
       xlabel(txt)    


     case 3      
       gp2=gp(:,lll:end);
          nihez2_SHY1=nihez_SHY1(lll:end);
          xr2_SHY1=xr_SHY1(lll:end);
         figure
        txt=['(P(t)-P(t-1))/P(t-1)=',num2str(B_SHY1(1)),'*(H(t)-H(t-1))/H(t-1)'];
        

          plot(gp2(2,:),'-+');
          hold on
        plot(nihez2_SHY1,'r.');
          legend('股价真实值','拟合股价');
       title('只考虑指数的收益率模型')
       txt1=['训练样本开始时间:',num2str(kd),';结束时间:',num2str(ld),'。共',num2str(d),'天数据'];
txt2=['样本决定系数(R^2):',num2str(STATS_SHY1(1)),';AIC值:',num2str(STATS_SHY1(4)),';股票和指数相关系数:',num2str(cor(1,2))];
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);

       xlabel(txt)  

figure
plot(xr2_SHY1);
   legend('相对误差','相对误差=100*(拟合值-真实值)/真实值');;

      title('只考虑指数的收益率模型')
       xlabel(txt)
figure
normplot(R_SHY1);
legend('误差对于正态分布的Q-Q图');
title('只考虑指数的收益率模型')
       xlabel(txt)
       
end
      
   end
   
   
M_SHY=get(handles.radiobutton4,'Value');
C_GP2=get(handles.checkbox1,'Value');
if M_SHY&C_GP2
%---5.收益率指数模型2:(P(t)-P(t-1))/P(t-1)=a1(H(t)-H(t-1))/H(t-1)+a2(Vp(t)*(1-exp(P(t-1)-P(t)))/(1+exp(H(t-1)-H(t)))
%[B_SHY2,BINT_SHY2,R_SHY2,RINT_SHY2,STATS_SHY2]=huigui(zhsh(1,:)',shy_gp',[shy_zhsh',obv1_gp'],alpha,p0',2);
[B_SHY2,BINT_SHY2,R_SHY2,RINT_SHY2,STATS_SHY2]=regress(shy_gp(ll+1:ll+d)',[shy_zhsh(ll+1:ll+d)',obv1_gp(ll+1:ll+d)'],alpha);

nih=B_SHY2'*[shy_zhsh',obv1_gp']';
       nihez_SHY2(1)=gp(2,1);
       for i=2:gp_length 
          nihez_SHY2(i)=gp(2,i-1)*(1+nih(i));
       end
        R_SHY2=nihez_SHY2-gp(2,:);

%-------计算D。W值
S=0; S1=R_SHY2(1)^2;
for i=2:gp_length
    S=S+R_SHY2(i)*R_SHY2(i-1);
    S1=S1+R_SHY2(i)^2;
end
STATS_SHY2(4)=2*(1-S/S1);
%-------计算对数似然值
L=-(gp_length)*(1+log(2*pi)+log(R_SHY2*R_SHY2'/gp_length))/2;
STATS_SHY2(5)=L;
%-------计算AIC值
STATS_SHY2(6)=2*(-L+2)/gp_length;
%-------计算SC值
STATS_SHY2(7)=2*(-L+2*log(gp_length))/gp_length;
%------------计算相对误差
xr_SHY2=100*R_SHY2'./gp(2,:)';
xr_min=min(xr_SHY2);%最小值
xr_max=max(xr_SHY2);%最大值

STATS_SHY2(8)=xr_min;
STATS_SHY2(9)=xr_max;

nu=mean(gp(2,:));
STATS_SHY2(10)=dot(gp(2,:)-nihez_SHY2,gp(2,:)-nihez_SHY2)/dot(gp(2,:)-nu,gp(2,:)-nu);

 switch states(3)
    case 0
        msgbox(' 请选择数据查看方式')
    case 1
       figure
        txt=['(P(t)-P(t-1))/P(t-1)=',num2str(B_SHY2(1)),'*(H(t)-H(t-1))/H(t-1)+',num2str(B_SHY2(2)),'*(Vp(t)*hp(t))'];
        txt1=['训练样本开始时间:',num2str(zhsh(1,ll+1)),';结束时间:',num2str(zhsh(1,d+ll)),'。共',num2str(d),'天数据'];
        txt2=['样本决定系数(R^2):',num2str(STATS_SHY2(1)),';AIC值:',num2str(STATS_SHY2(4)) ,';股票和指数相关系数:',num2str(cor(1,2))];
          disp('考虑股票成交量的收益率指数模型为:'); disp(txt);
          plot(gp(2,:),'-+');
          hold on
        plot(nihez_SHY2,'r.');
          legend('股价真实值','拟合股价');
      title('考虑成交量的收益率模型')
 xlabel(txt)
          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_SHY2);
   legend('相对误差','相对误差=100*(拟合值-真实值)/真实值');
      
 title('考虑成交量的收益率模型')
 xlabel(txt)
 hold on 
         plot(ll+d,xr_SHY2(ll+d),'k.','Markersize',20)
         plot(ll,xr_SHY2(ll),'k.','Markersize',20)
    
figure
normplot(R_SHY2);
legend('误差对于正态分布的Q-Q图');
title('考虑成交量的收益率模型')
 xlabel(txt)

       

    case 2
          gp1=gp(:,ll:end);
          nihez1_SHY2=nihez_SHY2(ll:end);
          xr1_SHY2=xr_SHY2(ll:end);
figure
        txt=['(P(t)-P(t-1))/P(t-1)=',num2str(B_SHY2(1)),'*(H(t)-H(t-1))/H(t-1)+',num2str(B_SHY2(2)),'*(Vp(t)*hp(t))'];
        txt1=['训练样本开始时间:',num2str(zhsh(1,ll+1)),';结束时间:',num2str(zhsh(1,d+ll)),'。共',num2str(d),'天数据'];
        txt2=['样本决定系数(R^2):',num2str(STATS_SHY2(1)),';AIC值:',num2str(STATS_SHY2(4)) ,';股票和指数相关系数:',num2str(cor(1,2))];
          disp('考虑股票成交量的收益率指数模型为:'); disp(txt);
          plot(gp1(2,:),'-+');
          hold on
        plot(nihez1_SHY2,'r.');
          legend('股价真实值','拟合股价');
      title('考虑成交量的收益率模型')

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -