oval 发表于 2012-4-11 20:18 
谢谢老师
load 'returns.txt'
T = size(returns,1);
nIndices = size(returns,2);
spec(1:nIndices) = garchset('Distribution' , 'T' , 'Display', 'off', ...
'VarianceModel', 'GJR', 'P', 1, 'Q', 1, 'R', 1);
residuals = NaN(T, nIndices); % preallocate storage
sigmas = NaN(T, nIndices);
for i = 1:nIndices
[spec(i) , errors, LLF, ...
residuals(:,i), sigmas(:,i)] = garchfit(spec(i), returns(:,i));
end
residuals = residuals ./ sigmas;
nPoints = 200; % # of sampled points of kernel-smoothed CDF
tailFraction = 0.1; % Decimal fraction of residuals allocated to each tail
OBJ = cell(nIndices,1);
for i = 1:nIndices
OBJ{i} = paretotails(residuals(:,i), tailFraction, 1 - tailFraction, 'kernel');
end
U = zeros(size(residuals));
for i = 1:nIndices
U(:,i) = OBJ{i}.cdf(residuals(:,i)); % transform margin to uniform
end
[R, DoF] = copulafit('t', U, 'Method', 'ApproximateML')
R =
1.0000 -0.0178
-0.0178 1.0000
DoF =
43.2848