Print

Print


Hi, I'm trying to re-estimate the Dynamic Nelson-Siegel model as in Diebold et al (2006) using the SsfPack routines.

The system is a multivariate gaussian linear model time invariant so its estimation should be  quite straightforward using Ssfpack, once the matrixes mOmega, mPhi, mDelta and mSigma have been created from the initial parameter vector. The total number of parameters is 36.  

However I've got problems with the maximization of the likelihood which  doesn't give back reasonable estimates or in other cases (I modify mSigma) I get a runtime error and I neither obtain any output. 
I'm a rookie with Ox and Ssfpack and if someone could give some advices I would be very grateful. 

I report the relative code below: 

#include <oxstd.h>
#import  <maximize>
#include <packages/ssfpack/ssfpack_ex.h>
#include "DNS2s.ox"

static decl mY, vMat, lambda, vP, T, t;
static decl mPhi, mOmega, mSigma, mDelta, dVar;

GetDNSp(const vP)
{
	decl T,Z,Q,R,d,c,P,a;
	decl slope, curvature;

	d = vP[0:2]; c = zeros(t,1);
	mDelta = d|c;

	T = vP[3:5]~vP[6:8]~vP[9:11];
	lambda = vP[sizer(vP)-1];
	slope = (1-exp(-lambda*vMat))./(lambda*vMat);
	curvature  = slope - exp(-lambda* vMat);
	Z = 1 ~ slope ~ curvature;
	mPhi = T|Z;


	Q = unvech(vP[12:17]);
	Q[0][0]= exp(vP[12]);
	Q[1][1] = exp(vP[15]);
	Q[2][2] = exp(vP[17]);
	R = zeros(t,t);
	R= setdiagonal(R, exp(vP[18:sizer(vP)-2]));
	mOmega = (Q ~ zeros (sizer(Q),sizec(R))) | (zeros(sizer(R),sizec(Q))~R);

	mSigma = (Q/(ones(sizer(Q))-T*T'))|d';
	//mSigma=ones(sizer(Q),sizer(Q))|d';
	
}

likelihood(const vP,const pdLik, const avScore, const amHess)
{
	GetDNSp(vP);
	SsfLik(pdLik, &dVar, mY', mPhi, mOmega, <>, mDelta);
	pdLik[0] /=sizec(mY);
	return 1;
}



main()
{
	decl mu, Phi, Q, R;
	decl ir, pdlik;
	lambda=0.0609; 
	mY=loadmat("DataOx/DieboldData.mat");
	T = sizer(mY); t = sizec(mY);
	vMat = <3,6, 9,	12,	15,	18,	21,	24,	30,	36,	48,	60,	72,	84,	96,	108, 120>';

	DNS2s(vMat, mY,"fix", &mu, &Phi, &Q, &R);
	//print("mu", mu, "Phi", Phi, "Q", Q, "R", R);
	vP=mu|vec(Phi)|vech(Q)|zeros(t,1)|lambda;
	vP[12]=0; vP[15]=0; vP[17]=0; 
	//println("size vP ",sizer(vP));
	println("vP", vP);
	//GetDNSp(vP);
	ir = MaxBFGS(likelihood, &vP, &pdlik, 0, TRUE);

	println(vP);

}