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

📄 gup.m

📁 对金融数据(股票
💻 M
📖 第 1 页 / 共 3 页
字号:
        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('考虑股票成交量的差分模型')
           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('考虑股票成交量的差分模型')
    end       
        
 M_B=get(handles.radiobutton4,'Value');
C_GP3=get(handles.radiobutton3,'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);
 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(zhsh(1,ll+1)),';结束时间:',num2str(zhsh(1,d+ll)),'。共',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)
         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_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)
end

M_SHY=get(handles.radiobutton5,'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);

figure
        txt=['(P(t)-P(t-1))/P(t-1)=',num2str(B_SHY1(1)),'*(H(t)-H(t-1))/H(t-1)'];
        txt1=['训练样本开始时间:',num2str(zhsh(1,ll+1)),';结束时间:',num2str(zhsh(1,d+ll)),'。共',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(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);
                
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)
       
   end
   
    
   
   M_SHY=get(handles.radiobutton5,'Value');
C_GP2=get(handles.radiobutton2,'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);
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)
 
end
         
M_SHY=get(handles.radiobutton5,'Value');
C_GP3=get(handles.radiobutton3,'Value');
if M_SHY&C_GP2
%---6.收益率指数模型3:(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)))+a3(Vh(t)*(1-exp(H(t-1)-H(t)))/(1+exp(H(t-1)-H(t)))
[B_SHY3,BINT_SHY3,R_SHY3,RINT_SHY3,STATS_SHY3]=regress(shy_gp(ll+1:ll+d)',[shy_zhsh(ll+1:ll+d)',obv1_gp(ll+1:ll+d)',obv1_zhsh(ll+1:ll+d)'],alpha);

nih=B_SHY3'*[shy_zhsh',obv1_gp',obv1_zhsh']';
       nihez_SHY3(1)=gp(2,1);
       for i=2:gp_length 
          nihez_SHY3(i)=gp(2,i-1)*(1+nih(i));
       end
        R_SHY3=nihez_SHY3-gp(2,:);
%-------计算D。W值
S=0; S1=R_SHY3(1)^2;
for i=2:gp_length
    S=S+R_SHY3(i)*R_SHY3(i-1);
    S1=S1+R_SHY3(i)^2;
end
STATS_SHY3(4)=2*(1-S/S1);
%-------计算对数似然值

L=-(gp_length)*(1+log(2*pi)+log(R_SHY3*R_SHY3'/gp_length))/2;
STATS_SHY3(5)=L;
%-------计算AIC值
STATS_SHY3(6)=2*(-L+3)/gp_length;
%-------计算SC值
STATS_SHY3(7)=2*(-L+3*log(gp_length))/gp_length;
%------------计算相对误差
xr_SHY3=100*R_SHY3'./gp(2,:)';
xr_min=min(xr_SHY3);%最小值
xr_max=max(xr_SHY3);%最大值
STATS_SHY3(8)=xr_min;
STATS_SHY3(9)=xr_max;
nu=mean(gp(2,:));
STATS_SHY3(10)=dot(gp(2,:)-nihez_SHY3,gp(2,:)-nihez_SHY3)/dot(gp(2,:)-nu,gp(2,:)-nu);
 figure
        txt=['(P(t)-P(t-1))/P(t-1)=',num2str(B_SHY3(1)),'*(H(t)-H(t-1))/H(t-1)+',num2str(B_SHY3(2)),'*(Vp(t)*hp(t))+',num2str(B_SHY3(2)),'*(VH(t)*hH(t))'];
        txt1=['训练样本开始时间:',num2str(zhsh(1,ll+1)),';结束时间:',num2str(zhsh(1,d+ll)),'。共',num2str(d),'天数据'];
        txt2=['样本决定系数(R^2):',num2str(STATS_SHY3(1)),';AIC值:',num2str(STATS_SHY3(4)) ,';股票和指数相关系数:',num2str(cor(1,2))];
          disp('考虑指数成交量的收益率模型:'); disp(txt);
          plot(gp(2,:),'-+');
          hold on
        plot(nihez_SHY3,'r.');
          legend('股价真实值','拟合股价');
        
           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);

         title('考虑指数成交量的收益率模型')
       xlabel(txt)
          hold on 
          plot(ll+d,gp(2,ll+d),'ko','Markersize',20);
          plot(ll,gp(2,ll),'ko','Markersize',20);
     
figure

plot(xr_SHY3);
   legend('相对误差','相对误差=100*(拟合值-真实值)/真实值');;
  title('考虑指数成交量的收益率模型')
       xlabel(txt)
 hold on 
         plot(ll+d,xr_SHY3(ll+d),'k.','Markersize',20)
         plot(ll,xr_SHY3(ll),'k.','Markersize',20)
   
figure
normplot(R_SHY3);
legend('误差对于正态分布的Q-Q图');
  title('考虑指数成交量的收益率模型')
       xlabel(txt)
       
   end
 
  M_DSHY=get(handles.radiobutton6,'Value');
C_GP1=get(handles.radiobutton1,'Value');
if M_DSHY&C_GP1
%---7.对数收益率-指数模型1:Log(P(t))-log(P(t-1))=a1Log(H(t))-log(H(t-1))
[B_DSHY1,BINT_DSHY1,R_DSHY1,RINT_DSHY1,STATS_DSHY1]=regress(db_gp(ll+1:ll+d)',db_zhsh(ll+1:ll+d)',alpha);
nih=B_DSHY1'*db_zhsh;
 nihez_DSHY1(1)=gp(2,1);
       for i=2:gp_length 
         nihez_DSHY1(i)=exp(nih(i)+log(gp(2,i-1)));
       end
        R_DSHY1=nihez_DSHY1-gp(2,:);

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

STATS_DSHY1(8)=xr_min;
STATS_DSHY1(9)=xr_max;
nu=mean(gp(2,:));
STATS_DSHY1(10)=dot(gp(2,:)-nihez_DSHY1,gp(2,:)-nihez_DSHY1)/dot(gp(2,:)-nu,gp(2,:)-nu);

figure
plot(gp(2,:),'-+');
hold on
plot(nihez_DSHY1,'r.');
legend('股价真实值','拟合股价');
txt=['ln(P(t)-P(t-1))=',num2str(B_DSHY1(1)),'*ln(H(t)-H(t-1))'];
txt1=['训练样本开始时间:',num2str(zhsh(1,ll+1)),';结束时间:',num2str(zhsh(1,d+ll)),'。共',num2str(d),'天数据'];
txt2=['样本决定系数(R^2):',num2str(STATS_DSHY1(1)),';AIC值:',num2str(STATS_DSHY1(4)) ,';股票和指数相关系数:',num2str(cor(1,2))];
 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);
title('只考虑指数的对数收益率指数模型')

xlabel(txt);
 disp('只考虑指数的对数收益率指数模型:'); disp(txt);
hold on 
plot(ll+d,gp(2,ll+d),'ko','Markersize',20)

⌨️ 快捷键说明

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