#NEWLINE# def varinversefilter( ar , nobs , version = 1 ) : #NEWLINE# #INDENT# 'creates inverse ar filter (MA representation) recursively\n\n    The VAR lag polynomial is defined by ::\n\n        ar(L) y_t = u_t  or\n        y_t = -ar_{-1}(L) y_{t-1} + u_t\n\n    the returned lagpolynomial is arinv(L)=ar^{-1}(L) in ::\n\n        y_t = arinv(L) u_t\n\n\n\n    Parameters\n    ----------\n    ar : array, (nlags,nvars,nvars)\n        matrix lagpolynomial, currently no exog\n        first row should be identity\n\n    Returns\n    -------\n    arinv : array, (nobs,nvars,nvars)\n\n\n    Notes\n    -----\n\n    ' #NEWLINE# ( nlags , nvars , nvarsex ) = ar . shape #NEWLINE# if ( nvars != nvarsex ) : #NEWLINE# #INDENT# print ( 'exogenous variables not implemented not tested' ) #NEWLINE# #UNINDENT# arinv = np . zeros ( ( ( nobs + 1 ) , nvarsex , nvars ) ) #NEWLINE# arinv [ 0 , : , : ] = ar [ 0 ] #NEWLINE# arinv [ 1 : nlags , : , : ] = ( - ar [ 1 : ] ) #NEWLINE# if ( version == 1 ) : #NEWLINE# #INDENT# for i in range ( 2 , ( nobs + 1 ) ) : #NEWLINE# #INDENT# tmp = np . zeros ( ( nvars , nvars ) ) #NEWLINE# for p in range ( 1 , nlags ) : #NEWLINE# #INDENT# tmp += np . dot ( ( - ar [ p ] ) , arinv [ ( i - p ) , : , : ] ) #NEWLINE# #UNINDENT# arinv [ i , : , : ] = tmp #NEWLINE# #UNINDENT# #UNINDENT# if ( version == 0 ) : #NEWLINE# #INDENT# for i in range ( ( nlags + 1 ) , ( nobs + 1 ) ) : #NEWLINE# #INDENT# print ( ar [ 1 : ] . shape , arinv [ ( i - 1 ) : ( i - nlags ) : ( - 1 ) , : , : ] . shape ) #NEWLINE# raise NotImplementedError ( 'waiting for generalized ufuncs or something' ) #NEWLINE# #UNINDENT# #UNINDENT# return arinv