Too many input arguments
2 次查看(过去 30 天)
显示 更早的评论
Hi,
Im using a code given below ab=nd it gives the following error.
Can someone please help me with it?
thanks
ERROR:
Error using gtest
Too many output arguments.
Error in test (line 37)
beta = gtest(Rt);
CODE:
clc;
clear;
% This program is for T=1000
T=1000;
B=1000;
R=1000;
ahead=10;
%generation the initial GARCH(1,1) data set.
a0 = 0.05; a1 = 0.1; b1 = 0.85;
epsi=zeros(3000,1);
simsig=zeros(3000,1);
simsig(1) = a0 ;
s=(simsig(1))^0.5;
epsi(1) = trnd(5,1) * s;
for i = 2:3000
simsig(i) = a0+ a1*(epsi(i-1))^2+ b1*simsig(i-1);
s=(simsig(i))^0.5;
epsi(i) = trnd(5,1) * s;
end
yt1=epsi.^2;
ytlast=epsi(3000)^2;
htlast=simsig(3000);
Rt=yt1(2001:3000);
beta = gtest(Rt);
function gtest(Rt)
%PURPOSE: estimates a GARCH(1,1) under the assumption that residuals are
%Student-t distributed
%Make sure that rtSP.mat is in the same location as this code.
%--------------------------------------------------------------------------
%USAGE : beta=test_ml5(Rt);
%--------------------------------------------------------------------------
%INPUT: Rt - Vector, the time series of returns (follow instruction on line
% 15 to use your own vector of data)
%--------------------------------------------------------------------------
%RETURN: beta - vector, GARCH(1,1) parameters of the maximum likelihood (w,alpha,beta,nu)
%--------------------------------------------------------------------------
tic;
m=mean(Rt);
Rt=Rt-m;
% parameters for GARCH: w, alpha, beta, nu
beta0=[0.01; 0.1; 0.8; 4];
lb=[0; 0.0001; 0.0001; 2 ];
ub=[1; 0.3; 0.99; 30];
A=[0 1 1 0]; %Ax<b
b=1;
[lb beta0 ub];
options=optimset('Diagnostics','on','Display','iter');
[beta,stderr1,vc,logl]=Max_lik(@likGARCH11T,beta0,'Hessian',A,b,[],[],lb,ub,[],options,Rt);
[beta,stderr2,vc,logl]=Max_lik(@likGARCH11T,beta0,'Sandwich',A,b,[],[],lb,ub,[],options,Rt);
[stderr1 stderr2];
toc
function l=likGARCH11T(b,rt)
% Computes the likelihood vector of a GARCH11
% presumes that Rt is a vector of centered returns
w = b(1);
alpha = b(2);
beta = b(3);
nu = b(4);
rt2 = rt.^2;
[T,K] = size(rt2);
ht = zeros(T,1);
ht(1) = sum(rt2)/T;
for i=2:T
ht(i) = w + alpha*rt2(i-1) + beta * ht(i-1);
end
sqrtht = sqrt(ht);
x = rt./sqrtht;
%*** Plug in Student-t
np1= (nu+1)/2;
nh = nu/2;
l1 = gammaln(np1);
l2 = gammaln(nh);
l3 = log(sqrtht);
l4 = 0.5*log(nu*pi);
l5 = np1*log(1 + (1/nu) * (x.^2));
l=l1-l2-l3-l4-l5;
0 个评论
采纳的回答
Walter Roberson
2013-9-3
You have coded
function gtest(Rt)
That declares that gtest() takes one item of input and returns nothing. Your code that calls on gtest() believes that gtest() returns something. You will need to decide which part of the code is correct.
5 个评论
Walter Roberson
2013-9-3
If the only place that calls likGARCH11T() is the gtest() code, then it is fine to include the definition of likGARCH11T() after the definition of gtest() in the the same gtest.m file.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Conditional Variance Models 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!