📄 qh.m
字号:
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)),';结束时间:',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(20,g_min+(g_max-g_min)*0.975,txt1);
text(20,g_min+(g_max-g_min)*0.95,txt2);
text(20,g_min+(g_max-g_min)*0.925,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 shuj
% --- 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.radiobutton3,'Value',1);
end% Hint: get(hObject,'Value') returns toggle state of radiobutton8% --- 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)load shuj
switch states(2)
case 0
msgbox('请选择训练方式');
case 1
s=get(handles.edit2,'string');
kd =str2num(s);
if kd==0
kd=zhsh(1,1);
ll=1;
else
for i=1:gp_length
if gp(1,i)==kd
ll=i;
end
end
end
if ll==0
msgbox('起始日期错误,请重新输入,0为从第一个数据开始');
end
case 2
s=get(handles.edit2,'string');
kd =str2num(s);
if kd==0
kd=zhsh(1,1);
ll=1;
else
for i=1:gp_length
if gp(1,i)==kd
ll=i;
end
end
end
if ll==0
msgbox('起始日期错误,请重新输入,0为从第一个数据开始');
end
end
save shuj
% 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)load shuj
switch states(2)
case 0
msgbox('请选择训练方式');
break;
case 1
s=get(handles.edit3,'string');
d =str2num(s);
if d<5
msgbox('训练时间太短,请重新输入');
else
lll=ll+d;
ld=zhsh(1,lll);
end
break
case 2
s=get(handles.edit3,'string');
ld =str2num(s);
if ld==0
ld=zhsh(1,end);
lll=gp_length-ll;
else
for i=1:gp_length
if gp(1,i)==ld
lll=i;
end
end
end
if lll==0
msgbox('结束日期错误,请重新输入,0为到最后一个数据');
end
break
end
d=lll-ll;
save shuj
% 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 shuj[name_gp,path_gp]=uigetfile('.xls','请选择要拟合期货数据');
ad_gp=[path_gp,name_gp];
gp=xlsread(ad_gp);
[name_zhsh,path_zhsh]=uigetfile('.xls','请选择另一种期货数据');
d_zhsh=[path_zhsh,name_zhsh];
zhsh=xlsread(d_zhsh);
[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 shuj
% --- 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)load shujgt = get(handles.radiobutton9,'Value');
if gt==1
states(2)=1;
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)
end
save shuj
% --- 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');
% Hint: get(hObject,'Value') returns toggle state of radiobutton10
if bt==1
load shuj
states(2)=2;
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','0')
set(handles.text6,'Visible','on')
set(handles.edit3,'Visible','on')
set(handles.radiobutton9,'Value',0)
save shuj
end
% Hint: get(hObject,'Value') returns toggle state of radiobutton10
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -