Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Voss
Voss el 9 de Abr. de 2022
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

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by