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

📄 ols.m

📁 Neural Network in Finance (神经网络在金融界:赢得预言性的优势)全部原码。内容包括预测与估计
💻 M
字号:
function [beta,se,resid,r2,rb2]=ols(X,y);
%OLS   Ordinary least-square estimation
%      [beta,se,resid,r2] calculates the ordinary least squares 
%      estimates, beta, for the equation(s):
% 
%           y=X*beta+u,     E[u]=0, E[u*u']=sigma^2 * I
%     
%      where y is a Txn matrix of T observations on the n dependent 
%      variables, X is a Txk matrix of T observations on k independent
%      variables, and u is a Txn matrix of residuals.  If requested, 
%      OLS also returns the standard errors of beta, se, the estimated 
%      residuals, u, the R^2 statistic, and the Rbar^2 statistic.
%

%      Ellen R. McGrattan, 10-13-87
%      Revised, 11-23-88, ERM
%
beta=(X'*X)\(X'*y);
if nargout>1;
  resid=y-X*beta;
  [T,k]=size(X);
  df=T-k;
  se=sqrt(diag(inv(X'*X)/df))*sqrt(diag(resid'*resid))';
end;
if nargout>3;
  p=X*((X'*X)\X');
  l=eye(T)-ones(T)/T;
  r2=((diag(y'*X*beta)-(sum(y)').^2/T).^2)./(diag(y'*l*y).*diag(y'*p*l*p*y));
  rb2=(T*r2-k)/df;
end;

⌨️ 快捷键说明

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