def vargenerate(ar, u, initvalues=None):
 (nlags, nvars, nvarsex) = ar.shape
 nlagsm1 = (nlags - 1)
 nobs = u.shape[0]
 if (nvars != nvarsex):
  print('exogenous variables not implemented not tested')
 if (u.shape[1] != nvars):
  raise ValueError('u needs to have nvars columns')
 if (initvalues is None):
  sar = np.zeros(((nobs + nlagsm1), nvars))
  start = nlagsm1
 else:
  start = max(nlagsm1, initvalues.shape[0])
  sar = np.zeros(((nobs + start), nvars))
  sar[(start - initvalues.shape[0]):start] = initvalues
 sar[start:] = u
 for i in range(start, (start + nobs)):
  for p in range(1, nlags):
   sar[i] += np.dot(sar[(i - p), :], (- ar[p]))
 return sar

def vargenerate ( ar , u , initvalues = None ) : ( nlags , nvars , nvarsex ) = ar . shape nlagsm1 = ( nlags - 1 ) nobs = u . shape [ 0 ] if ( nvars != nvarsex ) : print ( 'exogenous variables not implemented not tested' ) if ( u . shape [ 1 ] != nvars ) : raise ValueError ( 'u needs to have nvars columns' ) if ( initvalues is None ) : sar = np . zeros ( ( ( nobs + nlagsm1 ) , nvars ) ) start = nlagsm1 else : start = max ( nlagsm1 , initvalues . shape [ 0 ] ) sar = np . zeros ( ( ( nobs + start ) , nvars ) ) sar [ ( start - initvalues . shape [ 0 ] ) : start ] = initvalues sar [ start : ] = u for i in range ( start , ( start + nobs ) ) : for p in range ( 1 , nlags ) : sar [ i ] += np . dot ( sar [ ( i - p ) , : ] , ( - ar [ p ] ) ) return sar
generate an var process with errors u similar to gauss uses loop parameters ar : array matrix lagpolynomial u : array exogenous variable .