def varinversefilter(ar, nobs, version=1):
 (nlags, nvars, nvarsex) = ar.shape
 if (nvars != nvarsex):
  print('exogenous variables not implemented not tested')
 arinv = np.zeros(((nobs + 1), nvarsex, nvars))
 arinv[0, :, :] = ar[0]
 arinv[1:nlags, :, :] = (- ar[1:])
 if (version == 1):
  for i in range(2, (nobs + 1)):
   tmp = np.zeros((nvars, nvars))
   for p in range(1, nlags):
    tmp += np.dot((- ar[p]), arinv[(i - p), :, :])
   arinv[i, :, :] = tmp
 if (version == 0):
  for i in range((nlags + 1), (nobs + 1)):
   print(ar[1:].shape, arinv[(i - 1):(i - nlags):(-1), :, :].shape)
   raise NotImplementedError('waiting for generalized ufuncs or something')
 return arinv

def varinversefilter ( ar , nobs , version = 1 ) : ( nlags , nvars , nvarsex ) = ar . shape if ( nvars != nvarsex ) : print ( 'exogenous variables not implemented not tested' ) arinv = np . zeros ( ( ( nobs + 1 ) , nvarsex , nvars ) ) arinv [ 0 , : , : ] = ar [ 0 ] arinv [ 1 : nlags , : , : ] = ( - ar [ 1 : ] ) if ( version == 1 ) : for i in range ( 2 , ( nobs + 1 ) ) : tmp = np . zeros ( ( nvars , nvars ) ) for p in range ( 1 , nlags ) : tmp += np . dot ( ( - ar [ p ] ) , arinv [ ( i - p ) , : , : ] ) arinv [ i , : , : ] = tmp if ( version == 0 ) : for i in range ( ( nlags + 1 ) , ( nobs + 1 ) ) : print ( ar [ 1 : ] . shape , arinv [ ( i - 1 ) : ( i - nlags ) : ( - 1 ) , : , : ] . shape ) raise NotImplementedError ( 'waiting for generalized ufuncs or something' ) return arinv
creates inverse ar filter recursively the var lag polynomial is defined by :: ar(l) y_t = u_t or y_t = -ar_{-1}(l) y_{t-1} + u_t the returned lagpolynomial is arinv(l)=ar^{-1}(l) in :: y_t = arinv(l) u_t parameters ar : array .