フィルターのクリア

Continue running for loop for values that do not given an error

1 回表示 (過去 30 日間)
Wietze Zijpp
Wietze Zijpp 2022 年 4 月 9 日
コメント済み: Voss 2022 年 4 月 9 日
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.

採用された回答

Voss
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
Estimated EGARCH model is invalid. -- Occurred at (j,i) = (6,3) Estimated EGARCH model is invalid. -- Occurred at (j,i) = (6,6) Estimated EGARCH model is invalid. -- Occurred at (j,i) = (5,17)
AIC
AIC = 9×20
1.0e+20 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 2.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 2.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 2.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 NaN 0.0000 0.0000 0.0000 0.0000 0.0000 NaN 0.0000 0.0000 NaN 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 2.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 2.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
  2 件のコメント
Wietze Zijpp
Wietze Zijpp 2022 年 4 月 9 日
This is exactly what I was looking for !
Voss
Voss 2022 年 4 月 9 日
Perfect! Glad to help

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGARCH Model についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by