|
%Compute VaR according to model 2; GARCH-NIG:
%Vectors of returns for the different estimation periods:
ret1 = returns(1:2606); %10Y
ret2 = returns(1303:2606); %5Y
ret3 = returns(2086:2606); %2Y
%First specify the Garch model - GARCH(1,1)
Spec = garchset('P', 1, 'Q', 1);
%Then get parameters for the garch model for each estimation period every day out-of-sample, and calculate the VaR:
%10Y Estimation Period
f1 = numel(ret1);
S1 = 0;
for i=1:262
[alpha1, beta1, mu1, delta1] = nigpar(mean(ret1(0+i:f1-262+i)), ...
var(ret1(0+i:f1-262+i)), skewness(ret1(0+i:f1-262+i)), kurtosis(ret1(0+i:f1-262+i)));
niginv1 = niginv(0.99, alpha1, beta1, mu1, delta1);
[Coeff1,Errors1,LLF1,Innovations1,Sigmas1,Summary1] = ...
garchfit(Spec,ret1(0+i:f1-262+i));
[S1(i,1) S1(i,2)] = garchpred(Coeff1,ret1(0+i:f1-262+i),1);
VaR1(i,1) = S1(i,2) - (niginv1 * S1(i,1));
end
找到点代码,看能不能帮助你
|