📄 gup.m
字号:
plot(ll,gp(2,ll),'ko','Markersize',20)
figure
plot(xr_DSHY1);
legend('相对误差','相对误差=100*(拟合值-真实值)/真实值');
txt=['ln(P(t)-P(t-1))=',num2str(B_DSHY1(1)),'*ln(H(t)-H(t-1))'];
hold on
plot(ll+d,xr_DSHY1(ll+d),'k.','Markersize',20)
plot(ll,xr_DSHY1(ll),'k.','Markersize',20)
title('只考虑指数的对数收益率指数模型')
xlabel(txt);
figure
normplot(R_DSHY1);
legend('误差对于正态分布的Q-Q图');
title('只考虑指数的对数收益率指数模型')
xlabel(txt);
end
M_DSHY=get(handles.radiobutton6,'Value');
C_GP2=get(handles.radiobutton2,'Value');
if M_DSHY&C_GP2
%---8.对数收益率指数模型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_DSHY2,BINT_DSHY2,R_DSHY2,RINT_DSHY2,STATS_DSHY2]=regress(db_gp(ll+1:ll+d)',[db_zhsh(ll+1:ll+d)',obv1_gp(ll+1:ll+d)'],alpha);
nih=B_DSHY2'*[db_zhsh',obv1_gp']';
nihez_DSHY2(1)=gp(2,1);
for i=2:gp_length
nihez_DSHY2(i)=exp(nih(i)+log(gp(2,i-1)));
end
R_DSHY2=nihez_DSHY2-gp(2,:);
%-------计算D。W值
S=0; S1=R_DSHY2(1)^2;
for i=2:gp_length
S=S+R_DSHY2(i)*R_DSHY2(i-1);
S1=S1+R_DSHY2(i)^2;
end
STATS_DSHY2(4)=2*(1-S/S1);
%-------计算对数似然值
sigma2=std(R_DSHY2);
L=-(gp_length)*(1+log(2*pi)+log(R_DSHY2*R_DSHY2'/gp_length))/2;
STATS_DSHY2(5)=L;
%-------计算AIC值
STATS_DSHY2(6)=2*(-L+2)/gp_length;
%-------计算SC值
STATS_DSHY2(7)=2*(-L+2*log(gp_length))/gp_length;
%------------计算相对误差
xr_DSHY2=100*R_DSHY2'./gp(2,:)';
xr_min=min(xr_DSHY2);%最小值
xr_max=max(xr_DSHY2);%最大值
STATS_DSHY2(8)=xr_min;
STATS_DSHY2(9)=xr_max;
nu=mean(gp(2,:));
STATS_DSHY2(10)=dot(gp(2,:)-nihez_DSHY2,gp(2,:)-nihez_DSHY2)/dot(gp(2,:)-nu,gp(2,:)-nu);
figure
plot(gp(2,:),'-+');
hold on
plot(nihez_DSHY2,'r.');
legend('股价真实值','拟合股价');
txt=['ln(P(t)-P(t-1))=',num2str(B_DSHY2(1)),'*ln(H(t)-H(t-1))',num2str(B_DSHY2(2)),'(Vp(t)*hp(t))'];
txt1=['训练样本开始时间:',num2str(zhsh(1,ll+1)),';结束时间:',num2str(zhsh(1,d+ll)),'。共',num2str(d),'天数据'];
txt2=['样本决定系数(R^2):',num2str(STATS_DSHY2(1)),';AIC值:',num2str(STATS_DSHY2(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);
disp('考虑股票成交量的对数收益率指数模型为:'); disp(txt);
hold on
plot(ll+d,gp(2,ll+d),'ko','Markersize',20)
plot(ll,gp(2,ll),'ko','Markersize',20)
title('考虑股票成交量的对数收益率指数模型')
xlabel(txt);
figure
plot(xr_DSHY2);
legend('相对误差','相对误差=100*(拟合值-真实值)/真实值');
txt=['ln(P(t)-P(t-1))=',num2str(B_DSHY2(1)),'*ln(H(t)-H(t-1))',num2str(B_DSHY2(2)),'(Vp(t)*hp(t))'];
hold on
plot(ll+d,xr_DSHY2(ll+d),'k.','Markersize',20)
plot(ll,xr_DSHY2(ll),'k.','Markersize',20)
title('考虑股票成交量的对数收益率指数模型')
xlabel(txt);
figure
normplot(R_DSHY2);
legend('误差对于正态分布的Q-Q图');
title('考虑股票成交量的对数收益率指数模型')
xlabel(txt);
end
M_DSHY=get(handles.radiobutton6,'Value');
C_GP3=get(handles.radiobutton3,'Value');
if M_DSHY&C_GP3
%---9.对数收益率指数模型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_DSHY3,BINT_DSHY3,R_DSHY3,RINT_DSHY3,STATS_DSHY3]=regress(db_gp(ll+1:ll+d)',[db_zhsh(ll+1:ll+d)',obv1_gp(ll+1:ll+d)',obv1_zhsh(ll+1:ll+d)'],alpha);
nih=B_DSHY3'*[db_zhsh',obv1_gp',obv1_zhsh']';
nihez_DSHY3(1)=gp(2,1);
for i=2:gp_length
nihez_DSHY3(i)=exp(nih(i)+log(gp(2,i-1)));;
end
R_DSHY3=nihez_DSHY3-gp(2,:);
%-------计算D。W值
S=0; S1=R_DSHY3(1)^2;
for i=2:gp_length
S=S+R_DSHY3(i)*R_DSHY3(i-1);
S1=S1+R_DSHY3(i)^2;
end
STATS_DSHY3(4)=2*(1-S/S1);
%-------计算对数似然值
L=-(gp_length)*(1+log(2*pi)+log(R_DSHY3*R_DSHY3'/gp_length))/2;
STATS_DSHY3(5)=L;
%-------计算AIC值
STATS_DSHY3(6)=2*(-L+3)/gp_length;
%-------计算SC值
STATS_DSHY3(7)=2*(-L+3*log(gp_length))/gp_length;
%------------计算相对误差
xr_DSHY3=100*R_DSHY3'./gp(2,:)';
xr_min=min(xr_DSHY3);%最小值
xr_max=max(xr_DSHY3);%最大值
STATS_DSHY3(8)=xr_min;
STATS_DSHY3(9)=xr_max;
nu=mean(gp(2,:));
STATS_DSHY3(10)=dot(gp(2,:)-nihez_DSHY3,gp(2,:)-nihez_DSHY3)/dot(gp(2,:)-nu,gp(2,:)-nu);
figure
plot(gp(2,:),'-+');
hold on
plot(nihez_DSHY3,'r.');
legend('股价真实值','拟合股价');
txt=['ln(P(t)-P(t-1))=',num2str(B_DSHY3(1)),'*ln(H(t)-H(t-1))',num2str(B_DSHY3(2)),'(Vp(t)*hp(t))+',num2str(B_DSHY3(3)),'(VH(t)*h(t))'];
txt1=['训练样本开始时间:',num2str(zhsh(1,ll+1)),';结束时间:',num2str(zhsh(1,d+ll)),'。共',num2str(d),'天数据'];
txt2=['样本决定系数(R^2):',num2str(STATS_DSHY3(1)),';AIC值:',num2str(STATS_DSHY3(4))];
txt3=['股票和指数相关系数:',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);
text(10,g_min+(g_max-g_min)*0.875,txt3);
disp('考虑指数成交量的对数收益率指数模型:');
disp(txt);
hold on
plot(ll+d,gp(2,ll+d),'ko','Markersize',20)
plot(ll,gp(2,ll),'ko','Markersize',20)
title('考虑指数成交量的对数收益率指数模型')
xlabel(txt)
figure
plot(xr_DSHY3);
legend('相对误差','相对误差=100*(拟合值-真实值)/真实值');
title('考虑指数成交量的对数收益率指数模型')
xlabel(txt)
hold on
plot(ll+d,xr_DSHY3(ll+d),'k.','Markersize',20)
plot(ll,xr_DSHY3(ll),'k.','Markersize',20)
figure
normplot(R_DSHY3);
legend('误差对于正态分布的Q-Q图');
title('考虑指数成交量的对数收益率指数模型')
xlabel(txt)
end
save shuju% --- Executes on button press in radiobutton8.function radiobutton8_Callback(hObject, eventdata, handles)% hObject handle to radiobutton8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)C_A=get(hObject,'Value');
if C_A==1
set(handles.radiobutton1,'Value',1);
set(handles.radiobutton2,'Value',1);
set(handles.radiobutton3,'Value',1);
end% Hint: get(hObject,'Value') returns toggle state of radiobutton8% --- Executes on button press in pushbutton4.function pushbutton4_Callback(hObject, eventdata, handles)% hObject handle to pushbutton4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)load shuju
[name_gp,path_gp]=uigetfile('.xls','请选择股票数据');
ad_gp=[path_gp,name_gp];
gp=xlsread(ad_gp);
[n,m]=size(zhsh);
if n>m
zhsh=zhsh';
end
[zhsh_width,zhsh_length]=size(zhsh);
[k,l]=size(gp);
if k>l
gp=gp';
end
[gp_width,gp_length]=size(gp);
zhsh=sort1(zhsh);
gp=sort1(gp);
while gp_length~=zhsh_length
while zhsh(1,1)==0
zhsh(:,1)=[];
zhsh_length=zhsh_length-1;
end
while gp(1,1)==0
gp(:,1)=[];
gp_length=gp_length-1;
end
while zhsh(1,1)<gp(1,1)
zhsh(:,1)=[];
zhsh_length=zhsh_length-1;
end
while zhsh(1,1)>gp(1,1)
gp(:,1)=[];
gp_length=gp_length-1;
end
while zhsh(1,end)<gp(1,end)
gp(:,end)=[];
gp_length=gp_length-1;
end
while zhsh(1,end)>gp(1,end)
zhsh(:,end)=[];
zhsh_length=zhsh_length-1;
end
M_length=min(zhsh_length,gp_length);%找出指数和股价序列中较短的一个,以它作为比较次数
for i=1:M_length
if zhsh(1,i)<gp(1,i)
charu_gp=(gp(:,i)+gp(:,i-1))/2;
gp=charu(i,charu_gp,gp);
gp(1,i)=zhsh(1,i);
gp_length=gp_length+1;
else if zhsh(1,i)>gp(1,i)
charu_gp=(zhsh(:,i)+zhsh(:,i-1))/2;
zhsh=charu(i,charu_gp,zhsh);
zhsh(1,i)=gp(1,i);
zhsh_length=zhsh_length+1;
end
end
end
end
save shuju;
% --- Executes during object creation, after setting all properties.function edit1_CreateFcn(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit1_Callback(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)load shuju
val=get(handles.edit1,'string');
val=str2num(val);
save shuju
% Hints: get(hObject,'String') returns contents of edit1 as text% str2double(get(hObject,'String')) returns contents of edit1 as a double% --- Executes during object creation, after setting all properties.function edit2_CreateFcn(hObject, eventdata, handles)% hObject handle to edit2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit2_Callback(hObject, eventdata, handles)% hObject handle to edit2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit2 as text% str2double(get(hObject,'String')) returns contents of edit2 as a double% --- Executes during object creation, after setting all properties.function edit3_CreateFcn(hObject, eventdata, handles)% hObject handle to edit3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit3_Callback(hObject, eventdata, handles)% hObject handle to edit3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit3 as text% str2double(get(hObject,'String')) returns contents of edit3 as a double% --- Executes on button press in pushbutton5.function pushbutton5_Callback(hObject, eventdata, handles)% hObject handle to pushbutton5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)load shuju
[name_zhsh,path_zhsh]=uigetfile('.xls','请选择指数数据');
d_zhsh=[path_zhsh,name_zhsh];
zhsh=xlsread(d_zhsh);
save shuju;
% --- Executes on button press in radiobutton9.function radiobutton9_Callback(hObject, eventdata, handles)% hObject handle to radiobutton9 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hint: get(hObject,'Value') returns toggle state of radiobutton9gt = get(handles.radiobutton9,'Value');
if gt==1
load shuju
states(2)=1;
set(handles.radiobutton10,'Value',0)
set(handles.text5,'string','输入起始时间')
% Hint: get(hObject,'Value') returns toggle state of radiobutton9
set(handles.edit2,'string','0')
set(handles.text5,'Visible','on')
set(handles.edit2,'Visible','on')
set(handles.text6,'string','训练时间长度')
% Hint: get(hObject,'Value') returns toggle state of radiobutton9
set(handles.edit3,'string','250')
set(handles.text6,'Visible','on')
set(handles.edit3,'Visible','on')
set(handles.radiobutton10,'Value',0)
save shuju
end% --- Executes on button press in radiobutton10.function radiobutton10_Callback(hObject, eventdata, handles)% hObject handle to radiobutton10 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)bt = get(handles.radiobutton10,'Value');
if bt==1
% Hint: get(hObject,'Value') returns toggle state of radiobutton10
load shuju
states(2)=2;
set(handles.text5,'string','输入起始时间')
% Hint: get(hObject,'Value') returns toggle state of radiobutton9
set(handles.radiobutton9,'Value',0)
set(handles.edit2,'string','0')
set(handles.text5,'Visible','on')
set(handles.edit2,'Visible','on')
set(handles.text6,'string','输入结束时间')
% Hint: get(hObject,'Value') returns toggle state of radiobutton9
set(handles.edit3,'string','0')
set(handles.text6,'Visible','on')
set(handles.edit3,'Visible','on')
set(handles.radiobutton9,'Value',0)
save shuju
end% Hint: get(hObject,'Value') returns toggle state of radiobutton10
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -