我想用多元混合copula模型进行参数估计
运行代码显示:
未定义函数或变量 'copula_pdf'。
出错 M_Copulas (line 66)
copula_pdf=subs(copula_pdf,x(:),zdata(:));
实在是不懂
以下为完整代码,请大家帮我看看哪里问题~
function [p,l]= M_Copulas(family,zdata)
% Estimate parameters of different copulas
% Inputs: zdata --- t*n matrix:
% t is the length of time series
% n is the number of all time series
% --> Note that zdata is not original data,
% you should transform original data through
% marginal cumulative distribution function
% to get zdata, that is, each element in
% zdata belongs to the interval [0,1]
% copula --- options for different copulas:
% 'Clayton'
% 'Gumble'
% 'Frank'
%
% Output: p --- parameters in chosen copula
% l --- value of maximized log-likelihood function
%
zdata=xlsread('C:\Users\Administrator\Desktop\ttcdf.xlsx','Sheet1')
tic;
n=length(zdata(1,:));
t=length(zdata(:,1));
x=[];
y=sym(ones(1,n));
for j=1:t
for i=((j-1)*n+1):(j*n)
y(mod(i+n-1,n)+1)=['x' num2str(i)];
end
x=[x;y];
end
switch 'family'
case 'Clayton'
syms a;
ini=1;
lower=0.00001;
copula_pdf=((sum((x.^(-a))')')-n+1).^(-1/a);
for j=1:t
for i=((j-1)*n+1):(j*n)
copula_pdf(j)=diff(copula_pdf(j),x(j,mod(i+n-1,n)+1));
end
end
case 'Gumbel'
syms a;
ini=2;
lower=1.00001;
copula_pdf=exp(-((sum(((-log(x)).^a)'))').^(1/a));
for j=1:t
for i=((j-1)*n+1):(j*n)
copula_pdf(j)=diff(copula_pdf(j),x(j,mod(i+n-1,n)+1));
end
end
case 'Frank'
syms a;
ini=1;
lower=0.00001;
copula_pdf=-(1/a)*log(1+((prod((exp(-a*x)-1)'))')/(exp(-a)-1)^(n-1));
for j=1:t
for i=((j-1)*n+1):(j*n)
copula_pdf(j)=diff(copula_pdf(j),x(j,mod(i+n-1,n)+1));
end
end
end
copula_pdf=subs(copula_pdf,x(:),zdata(:));
copula_pdf=log(copula_pdf);
copula_pdf=sum(copula_pdf);
copula_pdf=-copula_pdf;
myfun=inline(copula_pdf);
[p,l] = fmincon(myfun,ini,[],[],[],[],lower,[],[]);
l=-l;
toc;


雷达卡





京公网安备 11010802022788号







