我试图在Oxmetrics中编写一个估算多变量GARCH模型的程序。 我的多变量GARCH模型具有无条件协方差矩阵(应该是X变量)作为输入,但我不确定如何在每次迭代时正确指定正确的矩阵。
我的程序现在看起来如下:
//Global variable; visible also in the likelihood function
decl X;
//Likelihood contributions
garch_likelihood_contributions(likval_t, par)
{
//Local variables
decl covar, lik, H,C,A, i;
//Parameters
C = par[0];
A = par[1];
//conditional covariance sequence
H = constant(.NaN,2,2);
H = C*C'+ exp(-A)*H[0][]+A*exp(-A)*X[0][];
H[][0] = 0; //Initial value
X[][0] = sumc(covar[m])/2071; // Not correct specified yet, should be the sample average of the covariance matrices //
for(decl i=1; i<columns(X); ++i)
{
H[0][i] = C*C'+ exp(-A)*H[i-1][]+A*exp(-A)*X[i-1][];
}
//likelihood contributions
lik = constant(.NaN,columns(X),1);
lik[0] = 0.5*log(determinant(H[][i-1]))+ 0.5*X[1][]*invert(H[][i-1])*X[1][]';
for(decl i=1;i<2071;++i)
{
lik[i] = 0.5*log(determinant(H[][i-1])) + 0.5*X[i-1][]*invert(H[][i-1])*X[i-1][]'; // her stod X[i+1]
}
// adFunc[0] = lik;
// return !ismissing(adFunc[0]);
}
decl likval_t;
//Return vector of likelihood-contributions
likval_t[0] = lik;
//Return success
return 1;
}
//Likelihood function
garch_likelihood(par, likval, avScore, amHessian)
{
//Local variables
decl likval_t;
//Likelihood contributions
garch_likelihood_contributions(&likval_t, par);
//Return likelihood-value
likval[0] = double(sumc(likval_t));
//Return success
return 1;
}
main()
{
//Declare variables
decl data;
decl loglik, par;
decl C, A, covar;
decl vol, r, S_t, K, P;
//Load data:
data = loadmat("covariances.in7")';
P = data[0][0:];
covar = data[0:1][0:];
X = constant(.NaN,2,2);
for (decl i = 0, i < columns(P), i+2 )
{
j[i] = <0,2;0,2>
X[i]= vech(j[i]);
}
//Initial values for parameters
par = 0.1|0.5; //i.e. (omega, alpha, beta). Try out different starting values!
//Settings for likelihood estimation
MaxControlEps(1e-6,1e-4);
MaxControl(20000, 1, 1);
//Maximize likelihood function
print("\n\n","Maximizing likelihood: \n");
MaxBFGS(garch_likelihood, &par, &loglik, 0, 1);
print("%r",{"C","A"}
,"%c",{"MLE"},
par);
println("\nMaximized likelihood: ", loglik);
}
在main中,您应该注意到我已经尝试将变量X指定为每次迭代的2x2矩阵。我们的想法是,对于每个i,循环应该分配数据表中的2个第一个cloumns和行&#34; covariances.in7&#34;进入X. 循环的步骤应为2,使得i = 1,3,5,7等。
请发表您的想法,我们非常感激。
致以最诚挚的问候,
克里斯蒂安
答案 0 :(得分:0)
我现在意识到我需要编写以下内容以使我的循环考虑每一秒的观察结果;
X = constant(.NaN,2,2);
for (decl i = 0, i < columns(P), ++i )
{
j[i] = <0,2;0,2>
X[i]= vech(j[i]);
i=i+1;
}