[Returnanalytics-commits] r2766 - pkg/PerformanceAnalytics/sandbox/Shubhankit/Week6-7/Code/Equivalent Matlab Code

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Aug 11 14:23:24 CEST 2013


Author: shubhanm
Date: 2013-08-11 14:23:23 +0200 (Sun, 11 Aug 2013)
New Revision: 2766

Added:
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week6-7/Code/Equivalent Matlab Code/effort.dat
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week6-7/Code/Equivalent Matlab Code/nwse.m
Log:
Week 6-7 : HAC Newey-west code and data for testing

Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/Week6-7/Code/Equivalent Matlab Code/effort.dat
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/Week6-7/Code/Equivalent Matlab Code/effort.dat	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/Week6-7/Code/Equivalent Matlab Code/effort.dat	2013-08-11 12:23:23 UTC (rev 2766)
@@ -0,0 +1,23 @@
+                 setting  effort   change
+   Bolivia            46       0        1
+   Brazil             74       0       10
+   Chile              89      16       29
+   Colombia           77      16       25
+   CostaRica          84      21       29
+   Cuba               89      15       40
+   DominicanRep       68      14       21
+   Ecuador            70       6        0
+   ElSalvador         60      13       13
+   Guatemala          55       9        4
+   Haiti              35       3        0
+   Honduras           51       7        7
+   Jamaica            87      23       21
+   Mexico             83       4        9
+   Nicaragua          68       0        7
+   Panama             84      19       22
+   Paraguay           74       3        6
+   Peru               73       0        2
+   TrinidadTobago     84      15       29
+   Venezuela          91       7       11
+
+

Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/Week6-7/Code/Equivalent Matlab Code/nwse.m
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/Week6-7/Code/Equivalent Matlab Code/nwse.m	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/Week6-7/Code/Equivalent Matlab Code/nwse.m	2013-08-11 12:23:23 UTC (rev 2766)
@@ -0,0 +1,42 @@
+function [V,S]=nwse(e,X,nlags)
+% PURPOSE: computes Newey-West adjusted heteroscedastic-serial
+%          consistent standard errors (only se's)
+%---------------------------------------------------
+% USAGE: [V,S] = nwse(e,X,nlag)
+% where: e = T x n vector of model residuls
+%        X = T x k matrix of independ vars
+%    nlags = lag length to use
+%---------------------------------------------------
+% RETURNS:
+%    V   is the Newey-West Var-Cov matrix
+%    S   is the spectral density of u = e.*X
+% --------------------------------------------------
+
+% written by:  Mike Cliff, Purdue Finance,  mcliff at mgmt.purdue.edu
+% CREATED 11/17/00
+% MODIFIED 1/23/01 Input e, X separtely; return V, S; df adjustment
+%          2/20/01 Allow for system of eqs (multiple e vectors)
+  
+if (nargin ~= 3); error('Wrong # of arguments to nwse'); end;
+
+[T,k] = size(X);
+n = cols(e);
+S = zeros(n*k,n*k);
+if k == 1 & X == ones(T,1)
+  u = e;
+else
+  u = [];
+  for i = 1:cols(e)
+    u = [u repmat(e(:,i),1,k).*X];
+  end
+end
+
+for lag = 0:nlags
+  rho = u(1:T-lag,:)'*u(1+lag:T,:)/(T-k);  
+  if lag >= 1, rho = rho + rho'; end
+  wt = 1 - lag/(nlags+1);
+  S = S + wt*rho;    
+end
+
+V = kron(eye(n),(X'*X/T)\eye(k));
+V = V*S*V/T;
\ No newline at end of file



More information about the Returnanalytics-commits mailing list