I am trying to estimate a rolling extreme shortfall matrix by looping. In the following code ESdynamic is crated for each column on the simulated matrix.
mu = [0 0 0 0 0 0];
A = rand(6);
Sigma= A * A';
rng('default')
Data = mvnrnd(mu,Sigma,1000);
r=Data(:,1);
Now, instead of representing r as just one column of data matrix, I want to out the entire code in a loop so that, at first Esdynamic is populated with column one, than on column 2... at the end we have a matrix of ESdynamic.
T= length(r);
conditionalvariance=[];
p=0.5;
VarMdl = garch(1,1);
Mdl = arima('ARLags',1,'Variance',VarMdl);
EstMdl = estimate(Mdl,r);
[res,v,logL] = infer(EstMdl,r);
conditionalvariance=[conditionalvariance,v];
Sigma=conditionalvariance;
ESdynamic=[];
VaRdynamic=[];
for P_Index = 1: +1: length(p)
P_Value = p(P_Index);
for J= 1:T
[Var_Normal, ES_Normal]=hNormalVaRES(Sigma(J),P_Value);
VaR = Var_Normal;
ES = ES_Normal;
disp(J)
disp('');
ESdynamic = [ESdynamic,ES];
I also want a Vardynamic matrix. how to ket the loop update it?
VaRdynamic = []
end
ES_Matrix(:,P_Index) = ESdynamic';
Now is it possible to put another loop so that the ESdynamic and VaRdynamic matrices, are generated for p = [0.5, 0.1, 0.05, 0.025, 0.01, 0.001] in a loop?
The plot compares all 6 columns of ESdynamic, for each ...please help
plot(ES_Matrix(:,P_Index));
hold on
ESdynamic = [];
end
hold off
function [VaR,ES] = hNormalVaRES(Sigma,p)
VaR = -norminv(p);
ES = -Sigma*quad(@(q)q.*normpdf(q),-6,-VaR)/p;
end
Your kind suggestions are requested.
0 Comments
Sign in to comment.