Continue running for loop for values that do not given an error
1 回表示 (過去 30 日間)
古いコメントを表示
Suppose I have the following line of code
Mdl_vol(1) = egarch('GARCHLags',1,'ARCHLags',1);
Mdl_vol(2) = egarch('GARCHLags',1:2,'ARCHLags',1);
Mdl_vol(3) = egarch('GARCHLags',1:3,'ARCHLags',1);
Mdl_vol(4) = egarch('GARCHLags',1,'ARCHLags',1:2);
Mdl_vol(5) = egarch('GARCHLags',1:2,'ARCHLags',1:2);
Mdl_vol(6) = egarch('GARCHLags',1:3,'ARCHLags',1:2);
Mdl_vol(7) = egarch('GARCHLags',1,'ARCHLags',1:3);
Mdl_vol(8) = egarch('GARCHLags',1:2,'ARCHLags',1:3);
Mdl_vol(9) = egarch('GARCHLags',1:3,'ARCHLags',1:3);
% AIC i stocks j models
for i = 1:20
for j = 1:9
EstMdl = estimate(Mdl_vol(j),monthlyerrorsi(:,i),'Display','off');
results = summarize(EstMdl);
AIC(j,i) = results.AIC;
end
end
Now I get the following error
Estimated EGARCH model is invalid.
Caused by:
Error using egarch/validateModel (line 789)
GARCH polynomial is not stationary.
So for some i = 1:20 any of the 9 models is invalid. However, I am wondering if there is a way to have the once that give an error display a 0 or NaN value. And for the models that do not given an error to obtain the right values.
0 件のコメント
採用された回答
Voss
2022 年 4 月 9 日
monthlyerrorsi = randn(100,20); % random monthlyerrorsi
Mdl_vol(1) = egarch('GARCHLags',1,'ARCHLags',1);
Mdl_vol(2) = egarch('GARCHLags',1:2,'ARCHLags',1);
Mdl_vol(3) = egarch('GARCHLags',1:3,'ARCHLags',1);
Mdl_vol(4) = egarch('GARCHLags',1,'ARCHLags',1:2);
Mdl_vol(5) = egarch('GARCHLags',1:2,'ARCHLags',1:2);
Mdl_vol(6) = egarch('GARCHLags',1:3,'ARCHLags',1:2);
Mdl_vol(7) = egarch('GARCHLags',1,'ARCHLags',1:3);
Mdl_vol(8) = egarch('GARCHLags',1:2,'ARCHLags',1:3);
Mdl_vol(9) = egarch('GARCHLags',1:3,'ARCHLags',1:3);
% AIC i stocks j models
for i = 1:20
for j = 1:9
try
EstMdl = estimate(Mdl_vol(j),monthlyerrorsi(:,i),'Display','off');
results = summarize(EstMdl);
AIC(j,i) = results.AIC;
catch ME
disp(sprintf('%s -- Occurred at (j,i) = (%d,%d)',ME.message,j,i));
AIC(j,i) = NaN;
end
end
end
AIC
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Conditional Variance Models についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!