def newey_west(m, max_lags, nobs, df, nw_overlap=False):
 Xeps = np.dot(m.T, m)
 for lag in range(1, (max_lags + 1)):
  auto_cov = np.dot(m[:(- lag)].T, m[lag:])
  weight = (lag / (max_lags + 1))
  if nw_overlap:
   weight = 0
  bb = (auto_cov + auto_cov.T)
  dd = ((1 - weight) * bb)
  Xeps += dd
 Xeps *= (nobs / (nobs - df))
 if (nw_overlap and (not is_psd(Xeps))):
  new_max_lags = int(np.ceil((max_lags * 1.5)))
  return newey_west(m, new_max_lags, nobs, df)
 return Xeps

def newey_west ( m , max_lags , nobs , df , nw_overlap = False ) : Xeps = np . dot ( m . T , m ) for lag in range ( 1 , ( max_lags + 1 ) ) : auto_cov = np . dot ( m [ : ( - lag ) ] . T , m [ lag : ] ) weight = ( lag / ( max_lags + 1 ) ) if nw_overlap : weight = 0 bb = ( auto_cov + auto_cov . T ) dd = ( ( 1 - weight ) * bb ) Xeps += dd Xeps *= ( nobs / ( nobs - df ) ) if ( nw_overlap and ( not is_psd ( Xeps ) ) ) : new_max_lags = int ( np . ceil ( ( max_lags * 1.5 ) ) ) return newey_west ( m , new_max_lags , nobs , df ) return Xeps
compute newey-west adjusted covariance matrix .