This is a very basic problem I am dealing with.
I have simulated a dataset with 6 variables and I want to measure dynamic extremen shortfall for each of the vectors.
I am trying to loop the following code in a way, that the final variable ES will present a matrix that will have T rows and 6 colums going through all data points in the simulated rectengular matrix.
clc
clear
%% Simulate data set
mu = [0 0 0 0 0 0];
A = rand(6);
Sigma= A * A';
%% Simulation of variables
rng('default') % For reproducibility
Data = mvnrnd(mu,Sigma,1000);
r=Data(:,1);
I want to use r = Data in that the estimation runs on all columns instead of on each column and the final ESmatrix plots all columns in one plot.
T= length(r);
conditionalvariance=[];
p= [0.025];
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=[];
bpoe=[];
for J= 1:T
[Var_Normal, ES_Normal]=hNormalVaRES(Sigma(J),p);
VaR=Var_Normal;
ES=ES_Normal;
disp(J)
disp('');
ESdynamic=[ESdynamic,ES];
VaRdynamic=[]
end
ES=ESdynamic;
Local Functions:
function [VaR,ES] = hNormalVaRES(Sigma,p)
% Compute VaR and ES for normal distribution
% See [4] for technical details
VaR = -norminv(p);
ES = -Sigma*quad(@(q)q.*normpdf(q),-6,-VaR)/p;
end
When I plot(ES), i want to have a plot of 6 variables.
Please kindly help me out with this looping issue.
