楼主: sucheng199099
4808 15

[问答] matlab做copula,运行fitmodel老出错。回复赠论坛币! [推广有奖]

  • 8关注
  • 0粉丝

已卖:436份资源

副教授

34%

还不是VIP/贵宾

-

威望
0
论坛币
907 个
通用积分
10.6200
学术水平
0 点
热心指数
5 点
信用等级
0 点
经验
6021 点
帖子
475
精华
0
在线时间
956 小时
注册时间
2009-11-14
最后登录
2025-2-10

楼主
sucheng199099 发表于 2012-10-31 00:14:51 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
RT:matlab做copula,运行fitmodel老出错。
老是提示:
??? Input argument "solver" is undefined.

Error in ==> fitModel at 39
switch solver


fitmodel代码如下:
if nargin == 2
    solver = 'fmincon';
end

switch solver
    case 'fmincon'
        % create starting values
        if isfield(spec,'comment')==1
            theta0 = spec.ctheta0;
        else
            theta0 = InputStartingValues(spec);
        end
        pause(.1);
        % create constraints + bounds matrices for fmincon
        [A, B, lower, upper] = CreateFminconConstraints(spec);
        %define optimization specifications
        options = optimset('Algorithm','interior-point','Display','iter','Hessian','bfgs','MaxFunEvals',12000);
        options = optimset(options,'FinDiffType','central','MaxIter',1500,'TolCon',10^-12,'TolFun',10^-5,'TolX',10^-5);
    case 'fminunc'
        %define optimization specifications
        options = optimset('Algorithm','interior-point','Display','iter','MaxFunEvals',9000,'MaxIter',1000,'TolCon',10^-12,'TolFun',10^-4,'TolX',10^-5,'FinDiffType','central');
        % invoke optimization procedure
end

        purp = spec.purpose;
        switch purp
            case 'fitGARCH'
                T = size(data,1); n = spec.size; m = spec.vecsize;
                parameters=zeros(m,n);
                LogL = zeros(1,n);
                exitflag = zeros(1,n);
                evalmodel = cell(1,n);
                GradHess = cell(1,n);
                udata = zeros(size(data));
                for i=1:n
                tic;
                if strcmp(solver,'fmincon')==1
               [parameters(:,i), LogL(i),exitflag(i),output,lambda,grad,hessian]= fmincon('GARCHLogL',theta0,A,B,[],[],lower,upper,[],options,data(:,i),spec,solver);
                yz = menu('calculate asymptotic standard errors?','yes','no');
                pause(.1)
                if yz == 1
                    [derivatives, RobVCV, VCV, hessian, RobStE]=CalcStErrors('GARCHLogL', parameters(:,i), data(:,i), grad,hessian,spec,solver);
                else
                    derivatives.grad = grad;
                    derivatives.hessian = hessian;
                end
                else
                % create starting values
                theta0 = InputStartingValues(spec);
                pause(.1);
                % make theta0 unconstrained
                theta0 = RescaleParameters(theta0, 2, spec);
                [params, LogL(i),exitflag(i),output,grad,hessian]= fminunc('GARCHLogL',theta0,options,data(:,i),spec,solver);
                parameters(:,i)=RescaleParameters(params,1,spec);
                yz = menu('calculate asymptotic standard errors?','yes','no');
                pause(.1)
                if yz == 1
                    [derivatives, RobVCV, VCV, hessian, RobStE]=CalcStErrors('GARCHLogL', parameters(:,i), data(:,i), grad, hessian, spec, solver);
                else
                    derivatives.grad = grad;
                    derivatives.hessian = hessian;
                    RobStE = [];
                end
                end
                if yz == 1
                derivatives.grad = grad;
                derivatives.hessian = hessian;
                GradHess{1,i}=derivatives;
                else
                GradHess{1,i}=derivatives;
                end
                [AIC,BIC] = aicbic(-LogL(i),m,T);
                output.AIC = AIC;
                output.BIC = BIC;
                output.LogL = -LogL(i);
                evalmodel{1,i} = output;
                [dum, dum, dum, dum, udata(:,i)]=GARCHLogL(parameters(:,i),data(:,i),spec,'fmincon');
                output.TimeInSeconds = toc;
                DisplayResults(parameters(:,i),RobStE,output)
                if i<n
                fprintf(1,'Press any key to continue\n\n')
                pause
                end

                end
                varargout{1} = udata;
            case 'fitCopula'
                tic
                T = size(data,1); m = size(spec.ctheta0,1);
                if strcmp(solver,'fmincon')==1
                [parameters, LogL,exitflag,output,lambda,grad,hessian]= fmincon('CopulaLogL',theta0,A,B,[],[],lower,upper,[],options,data,spec,solver);
                [dum,dum,Rt]=CopulaLogL(parameters,data,spec, 'fmincon');
                if isfield(spec,'comment')==1
                    yz = 0;
                else
                    yz = menu('calculate asymptotic standard errors?','yes','no');
                end
                pause(.1)
                if yz == 1
                    [derivatives, RobVCV, VCV, hessian, RobStE]=CalcStErrors('CopulaLogL', parameters, data, grad, hessian, spec, 'fmincon');
                else
                    derivatives.grad = grad;
                    derivatives.hessian = hessian;
                    RobStE = [];
                end
                else
                % create starting values
                theta0 = InputStartingValues(spec);
                pause(.1);
                % make theta0 unconstrained
                theta0 = RescaleParameters(theta0, 2, spec);
                [params, LogL,exitflag,output,grad,hessian]= fminunc('CopulaLogL',theta0,options,data,spec,solver);
                parameters=RescaleParameters(params,1,spec);
                [dum,dum,Rt]=CopulaLogL(parameters,data,spec, 'fmincon');
                yz = menu('calculate asymptotic standard errors?','yes','no');
                pause(.1)
                if yz == 1
                    [derivatives, RobVCV, VCV, hessian, RobStE]=CalcStErrors('CopulaLogL', parameters, data, grad, hessian, spec, 'fminunc');
                else
                    derivatives.grad = grad;
                    derivatives.hessian = hessian;
                    RobStE = [];
                end
                end


求大神高手指导,感激不尽!

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:MATLAB Copula model opula atlab matlab

[img][/img]

沙发
sucheng199099 发表于 2012-10-31 00:15:32
接上:
         if yz == 1
                derivatives.grad = grad;
                derivatives.hessian = hessian;
                GradHess=derivatives;
                else
                GradHess=derivatives;
                end
                GradHess.grad = grad;
                [AIC,BIC] = aicbic(-LogL,m,T);
                output.AIC = AIC;
                output.BIC = BIC;
                output.LogL = -LogL;
                output.Rt = Rt;
                output.TimeInSeconds = toc;
                evalmodel = output;
                DisplayResults(parameters,RobStE,output)
                varargout{1}=[];
            case 'fitCopulaGARCH'
               tic
               T = size(data,1); m = size(spec.ctheta0,1);
               if strcmp(solver,'fmincon')==1
               [parameters, LogL,exitflag,output,lambda,grad,hessian]= fmincon('CopulaGARCHLogL',theta0,A,B,[],[],lower,upper,[],options,data,spec,solver);
               [dum, dum, tvpars] = CopulaGARCHLogL(parameters,data,spec,'fmincon');
               yz = menu('calculate asymptotic standard errors?','yes','no');
               pause(.1)
               if yz == 1
                   [derivatives, RobVCV, VCV, hessian, RobStE]=CalcStErrors('CopulaGARCHLogL', parameters, data, grad, hessian, spec, 'fmincon');
               end
               else
                % create starting values
                theta0 = InputStartingValues(spec);
                %theta0 = spec.theta0;
                pause(.1);
                % make theta0 unconstrained
                theta0 = RescaleParameters(theta0, 2, spec);
                [params, LogL,exitflag,output,grad,hessian]= fminunc('CopulaGARCHLogL',theta0,options,data,spec,solver);
                parameters=RescaleParameters(params,1,spec);
                [dum, dum, tvpars] = CopulaGARCHLogL(parameters,data,spec,'fmincon');
                %yz = menu('calculate asymptotic standard errors?','yes','no');
                yz = 1;
                pause(.1)
                if yz == 1
                    [derivatives, RobVCV, VCV, hessian, RobStE]=CalcStErrors('CopulaGARCHLogL', parameters, data, grad, hessian,spec, 'fminunc');
                else
                    derivatives.grad = grad;
                    derivatives.hessian = hessian;
                end
                end
                if yz == 1
                derivatives.grad = grad;
                derivatives.hessian = hessian;
                GradHess=derivatives;
                else
                GradHess=derivatives;
                end
                GradHess.grad = grad;
                [AIC,BIC] = aicbic(-LogL,m,T);
                output.AIC = AIC;
                output.BIC = BIC;
                output.LogL = -LogL;
                output.TimeInSeconds = toc;
                output.exitflag = exitflag;
                output.tvpars = tvpars;
                evalmodel = output;
                DisplayResults(parameters,RobStE,output)
                varargout{1}=[];
            case 'fitCopVine'
               tic
               T = size(data,1); m = size(spec.ctheta0,1);
               if strcmp(solver,'fmincon')==1
               [parameters, LogL,exitflag,output,lambda,grad,hessian]= fmincon('CopulaVineLogL',theta0,A,B,[],[],lower,upper,[],options,data,spec,solver);
               yz = menu('calculate asymptotic standard errors?','yes','no');
               pause(.1)
               if yz == 1
                   [derivatives, RobVCV, VCV, hessian, RobStE]=CalcStErrors('CopulaVineLogL', parameters, data, grad, hessian, spec, 'fmincon');
               end
               else
                % create starting values
                theta0 = InputStartingValues(spec);
                pause(.1);
                % make theta0 unconstrained
                theta0 = RescaleParameters(theta0, 2, spec);
                [params, LogL,exitflag,output,grad,hessian]= fminunc('CopulaVineLogL',theta0,options,data,spec,solver);
                parameters=RescaleParameters(params,1,spec);
                yz = menu('calculate asymptotic standard errors?','yes','no');
                pause(.1)
                if yz == 1
                    [derivatives, RobVCV, VCV, hessian, RobStE]=CalcStErrors('CopulaVineLogL', parameters, data, grad, hessian,spec, 'fminunc');
                else
                    derivatives.grad = grad;
                    derivatives.hessian = hessian;
                    RobStE=[];
                end
                end
                if yz == 1
                derivatives.grad = grad;
                derivatives.hessian = hessian;
                GradHess=derivatives;
                else
                GradHess=derivatives;
                end
                GradHess.grad = grad;
                [AIC,BIC] = aicbic(-LogL,m,T);
                output.AIC = AIC;
                output.BIC = BIC;
                output.LogL = -LogL;
                output.TimeInSeconds = toc;
                evalmodel = output;
                DisplayResults(parameters,RobStE,output)
                varargout{1}=[];
        end
    end
[img][/img]

藤椅
wzw03 发表于 2012-10-31 00:52:56
不知道问题出在哪里

板凳
koala500 发表于 2012-10-31 09:10:50
不懂。。
加油

报纸
yger 在职认证  发表于 2012-11-7 16:14:27
楼主好厉害,这程序看得头晕。。

地板
erningzhao 发表于 2012-11-17 14:52:39
只图金币

7
tulipsliu 在职认证  发表于 2012-11-17 19:15:59
可以运行的;
劳动经济学

8
beibei2004213 发表于 2012-11-19 13:28:16
支持,顶一下!

9
小令 发表于 2013-3-11 15:41:14
看不懂

10
fangbochao 发表于 2013-3-13 12:59:29
厉害

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-9 23:14