⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 neweywest.m

📁 Neural Network in Finance (神经网络在金融界:赢得预言性的优势)全部原码。内容包括预测与估计
💻 M
字号:
function omegahat = NeweyWest(Z,nlags)

% Returns the Newey-West estimator of the asymptotic variance matrix
% INPUTS: Z, a nxk matrix with rows the vector zt'
%         nlags, the number of lags
%
% OUTPUTS: omegahat, the Newey-West estimator of the covariance matrix


[n,k] = size(Z);

% de-mean the variables
Z = Z - ones(size(Z,1),1)*mean(Z);

gamma = -999*ones(nlags,k);
samplevar = Z'*Z/n; % sample variance
omegahat = samplevar;
if nlags > 0
   % sample autocovariances
   for ii = 1:nlags
      Zlag = [zeros(ii,k);Z(1:n-ii,:)];
      gamma = (Z'*Zlag +Zlag'*Z)/n;
      weights = 1 - (ii/(nlags+1));
      omegahat = omegahat + weights*gamma;
   end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -