• 大小: 2KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-04-17
  • 语言: Matlab
  • 标签: ARMA模  白噪声  

资源简介

时间序列ARMA建模实例,包含对数据的平稳性检验、白噪声检验及依据ARMA模型的预测。

资源截图

代码片段和文件信息

 Load_Data_Path=‘Trade_Data.txt‘;
% Load_Data_Path=‘Industrial_Data.txt‘;
Predict_Num=16;
Test_Num=58-Predict_Num;

 [YearPrice_in]=textread(Load_Data_Path‘%s%f‘‘headerlines‘1);
% [Price_in]=textread(Load_Data_Path‘%f‘‘headerlines‘1);
Price=Price_in(1:Test_Num);
l=1;
n=1:(Test_Num-l);
figure(1)
 subplot(311);
plot(Price_in);
 subplot(312);
 autocorr(Price_in(:)20)
 subplot(313);
 parcorr(Price_in(:)20)

[h1pvalue1]=lbqtest(Price[510152025]0.05)
[h2pvalue2]=adftest(Price‘alpha‘0.05‘model‘‘TS‘‘Lags‘0:6)

%     Price1=log(Price)
%      subplot(312);
%  plot(nPrice1(:));

%  Price_diffl=diff(Pricel)
% [hpvalue]=adftest(Price_diff‘alpha‘0.05‘model‘‘TS‘‘Lags‘0:6)
 Price_lg=log(Price);
  Price_diffl=diff(Price_lgl);
 if l==2
     Price_diffl_1=diff(Price_lgl-1);
 end
%     Price_diffl_2=diff(Price_lgl-2);
  
 [h3pvalue3]=adftest(Price_diffl‘alpha‘0.05‘model‘‘TS‘‘Lags‘0:6)
figure(2)
 subplot(311);
 plot(nPrice_diffl(:));
 subplot(312);
 autocorr(Price_diffl(:)20)
 subplot(313);
 parcorr(Price_diffl(:)20)

 %确定阶数
 AIC=10^4;
 for i=0:3
     for j=0:6
         Spec=garchset(‘R‘i‘M‘j‘Display‘‘off‘);
         [EstSpecEstSElogL]=garchfit(SpecPrice_diffl);
         Num=garchcount(EstSpec);
         [aic(i+1j+1)bic(i+1j+1)]=aicbic(logLNumlength(Price_diffl));
         if AIC>aic(i+1j+1)
             AIC=aic(i+1j+1);
             p=i;
             q=j;
         end
     end
 end

 %模型参数估计
 Spec_Model=garchset(‘R‘p‘M‘q‘Display‘‘off‘);
 [EstSpecEstSElogLesigmasummary]=garchfit(SpecPrice_diffl);
 
 %求预报值
[sigmaForecastDiff_Forecast]=garchpred(EstSpecPrice_difflPredict_Num);
% Price_diffl_F1=cumsum(Diff_Forecast)+Diff_Forecast(1);
% n1=[Diff_Forecast(1)];
% Price_diffl_F2=[n1;Price_diffl_F1];
if l==1
    Price_diffl_F=exp(Price_lg(Test_Num)+cumsum(Diff_Forecast));

end   
if l==2 
Price_diffl_F=exp(Price_lg(Test_Num)+cumsum(Price_diffl_1(Test_Num-1)+cumsum(Diff_Forecast)));
end
%  Price_diffl_F=exp(Price_lg(Test_Num)+(Price_diffl_1(Test_Num-2)+cumsum(Price_diffl_2(Test_Num-1)+cumsum(Diff_Forecast))));

 
%  
% Price_lg1=log(Price_in);
%   Price_diff1=diff(Price_lg1l);
% n1=1:58-l;
% n2=Test_Num+1:58;
% figure(2);
% plot(n1 Price_diff1);
% hold on;
% plot(n2Diff_Forecast‘r‘);
[abcde]=regress(Diff_ForecastPrice_diffl(Test_Num-l-Predict_Num+1:Test_Num-l));
[h4pvalue4]=lbqtest(c[123456]0.05)


n1=1:58;
n2=Test_Num+1:58;
figure(3);
plot(n1Price_in);
hold on;
plot(n2Price_diffl_F‘r‘);
x=[‘ARMA模型的阶数为AR(‘num2str(p)‘)MA(‘num2str(q)‘)‘];
y=[‘原始数据白噪声检验的结果为:‘num2str(h1)‘原始数据平稳性检验的结果为‘num2str(h2)‘处理后数据平稳性检验的结果为‘num2str(h3)‘残差序列白噪声检验的结果为:‘num2str(h4)];
% disp( x)
msgbox(x);
msgbox(y);


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        2896  2014-03-22 12:20  Time_Series_1.m
     文件         740  2013-04-12 08:27  Trade_Data.txt

评论

共有 条评论