-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtsCopulaFit.m
More file actions
31 lines (27 loc) · 1.22 KB
/
tsCopulaFit.m
File metadata and controls
31 lines (27 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function copulaParam = tsCopulaFit(copulaFamily, uProb)
if strcmpi(copulaFamily, 'gaussian')
copulaParam = corr(uProb, 'type', 'Spearman'); % apparently works bettern than copulafit
elseif strcmpi(copulaFamily, 'gumbel') || strcmpi(copulaFamily, 'clayton') || strcmpi(copulaFamily, 'frank')
nSeries = size(uProb, 2);
copulaParam = ones(nSeries);
kendalT = corr(uProb, 'type', 'Kendall');
if strcmpi(copulaFamily, 'gumbel')
kendalT(triu(kendalT) < 0) = 0;
% Replace negatives in the lower triangle
kendalT(tril(kendalT) < 0) = 0;
end
for iSeries1 = 1:nSeries
for iSeries2 = iSeries1+1:nSeries
copulaParam(iSeries1, iSeries2) = copulaparam(copulaFamily,kendalT(iSeries1,iSeries2));
copulaParam(iSeries2, iSeries1) = copulaParam(iSeries1, iSeries2);
end
end
if strcmpi(copulaFamily, 'gumbel')
copulaParam(triu(copulaParam) == Inf) = 1;
% Replace negatives in the lower triangle
copulaParam(tril(copulaParam) == Inf) = 1;
end
else
error('copulaFamily not supported: ' + copulaFamily);
end
end