For Programmers: Free Programming Magazines  


Home > Archive > Matlab > September 2006 > minz minimization tries complex valued parameters









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author minz minimization tries complex valued parameters
Anders Wilhelmsson

2006-09-29, 8:06 am

Hi everyone,

I'm using the minz function written by Professor Mike Cliff
(available at <http://mcliff.cob.vt.edu/>
to estimate the conditonal density model of Hansen 1994.

After a couple of interations the mintz function tries complexed
valued parameters which are not allowed in the model. Does anyone
know how to avoid this?

This is the funtion to be minimized:

****************************************
*********
% Conditonal Density model Hansen 1994
function ML = MLGARCHGT(b,infoz,stat,varargin)

% setting startvalues

my=b(1); alpha0=b(2); alpha1=b(3); beta=b(4);
ar=b(5); a1=b(6); b1=b(7); c1=b(8); d1=b(9);
% boundaries for the logistic transformation
Ldf=2.1; Udf=30; Lskew=-0.9; Uskew=0.9;

lvar = length(varargin);
y = varargin{lvar};
y =y';
NoObs = length(y);
h=zeros(1,NoObs);
% initial parameter values
res(1)=0; h(1)= alpha0/(1-alpha1-beta);
estdf(1)=20; estskew(1)=0;
% define some equations
res(2:NoObs)= y(2:NoObs)-my-ar.*y(1:NoObs-1);
estdf(2:NoObs)=a1 + (b1.*res(1:NoObs-1));
estskew(2:NoObs)=c1 + (d1.*res(1:NoObs-1));

%Logistic transformations to place bounds on the shape parameters
df = Ldf + ((1+exp(-estdf)).^-1).*(Udf-Ldf);
lambda = Lskew + ((1+exp(-estskew)).^-1).*(Uskew-Lskew);
lnc = gammaln((df+1)./2)-0.5*log(pi.*(df-2))-gammaln(df./2);
a = 4.*lambda.*exp(lnc).*(df-2)./(df-1);
bb = (abs(1+3.*(lambda.^2)-a.^2)).^0.5;

% since h is defined iteratativly I can't think of a way to avoid the
% loop
for i = 2:NoObs
h(i) = alpha0 + alpha1*(res(i-1)^2)+beta*h(i-1);
end
zstand = res./(h.^0.5);
paren = bb.*res./(h.^0.5)+(a./(1-lambda.*sign(-a./bb-zstand)));
loggan = 1+(1./(df-2)).*paren.^2;
% ML in matrix form (faster than loop), minz minimizes so - sign
added

ettor = ones(length(h)-1,1);
ML =
- (log(bb(2:2518))*ettor+lnc(2:2518)*ettor
-((((df(2:2518)+1)./2).*log(l
oggan(2:2518)))*ettor)-(0.5.*log(h(2:2518)))*ettor);

This is the script calling the function

% setting options
infoz.call='mle';
infoz.func='MLGARCHG';
infoz.hess='bfgs';
infoz.ftol=1e-09;
infoz.step ='step2';
infoz.h0 = 1;
infoz.prt = 0;
% loading data
load 'G:\skol laptop 14 juli 06\wilhelmsson\Density
forecasting\matlab\garchdata.txt'
y = garchdata;
% setting startvalues
b=[0.05 0.01 0.039 0.64 0.0647 -1.464 -0.453 0.0098 0.153];

% doing the acutal optimization
tic;[opi,infoz,stat] = minz(b',@MLGARCHGT,infoz,y);toc

Best regads,
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com