大家好,目前我需要用matlab做garch-bekk模型,求两组金融高频数据的方差和协方差,以求套保比率。
现在,我已经找到了bekk的工具包,里面的程序如下,是一个m文件,我想知道,我怎样将我的两组数据带入,调用m文件,run出结果。
因为之前都没用过这个软件,想知道详细步骤,万分感谢,比较急,论坛币不多,希望能得到回复~或者用其它软件怎么做,有人知道么?
function [ll,lls,Ht] = bekk_likelihood(parameters,data,dataAsym,p,o,q,backCast,backCastAsym,type)
% Likelihood for BEKK(p,q) multivarate volatility model estimation
%
% USAGE:
% [LL,LLS,HT] = bekk_likelihood(PARAMETERS,DATA,P,O,Q,BACKCAST,TYPE)
%
% INPUTS:
% PARAMETERS - Vector of parameters required to compute the (negative) of the log-likelihood
% DATA - K by K by T array of data
% DATAASYM - K by K by T array of asymmetric data
% P - Positive, scalar integer representing the number of symmetric innovations
% O - Non-negative, scalar integer representing the number of asymmetric innovations
% Q - Non-negative, scalar integer representing the number of conditional covariance lags
% BACKCAST - K by K matrix to use for back casting
% TYPE - Number indicating type:
% 1 - Scalar
% 2 - Diagonal
% 3 - Full
%
% OUTPUTS:
% LL - The log likelihood evaluated at the PARAMETERS
% LLS - A T by 1 vector of log-likelihoods
% HT - A [K K T] dimension matrix of conditional covariances
%
% COMMENTS:
%
% See also BEKK
% Copyright: Kevin Sheppard
%
kevin.sheppard@economics.ox.ac.uk
% Revision: 1 Date: 3/27/2012
% Get the parameters together
T = size(data,3);
k = size(data,2);
[C,A,G,B] = bekk_parameter_transform(parameters,p,o,q,k,type);
Ht = zeros(k,k,T);
lls = zeros(T,1);
logLikConst = k*log(2*pi);
for i=1:T
Ht(:,:,i) = C;
for j=1:p
if (i-j)<=0
Ht(:,:,i) = Ht(:,:,i) + A(:,:,j)'*backCast*A(:,:,j);
else
Ht(:,:,i) = Ht(:,:,i) + A(:,:,j)'*data(:,:,i-j)*A(:,:,j);
end
end
for j=1:o
if (i-j)<=0
Ht(:,:,i) = Ht(:,:,i) + G(:,:,j)'*backCastAsym*G(:,:,j);
else
Ht(:,:,i) = Ht(:,:,i) + G(:,:,j)'*dataAsym(:,:,i-j)*G(:,:,j);
end
end
for j=1:q
if (i-j)<=0
Ht(:,:,i) = Ht(:,:,i) + B(:,:,j)'*backCast*B(:,:,j);
else
Ht(:,:,i) = Ht(:,:,i) + B(:,:,j)'*Ht(:,:,i-j)*B(:,:,j);
end
end
lls(i) = 0.5*(logLikConst + log(det(Ht(:,:,i))) + sum(diag(Ht(:,:,i)^(-1)*data(:,:,i))));
end
ll = sum(lls);
if isnan(ll) || isinf(ll) || ~isreal(ll)
ll = 1e7;
end