Too many input arguments

2 ビュー (過去 30 日間)
dav
dav 2013 年 9 月 3 日
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;

採用された回答

Walter Roberson
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
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.
dav
dav 2013 年 9 月 3 日
thank you very much. Finally, I got this function gtest(Rt) code from an online post there, they had put a ";" right in front of function l=likGARCH11T(b,rt)
(function l=likGARCH11T(b,rt);)
is that necessary?
Again, thank you for all your help!
dav

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConditional Variance Models についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by