def setup_class(cls): # VAR with 2 variables and 3 lags ar = [[[.1, .2], [.3, .4]], [[.5, .6], [.7, .8]], [[.9, 0], [-.1, -.2]]] arparams = np.array(ar) ma = [[0, .1], [.2, -.3]] maparams = np.array(ma) # Note: The __init__ call should reshape this from (2, 2) to (1, 2, 2) cls.varma = wold.VARParams(arparams, maparams) intercept = np.array([1.2, 3.4]) cls.varma2 = wold.VARParams(arparams, maparams, intercept)
def test_neqs_mismatch(self): # The number of equations implied by ar shape doesn't match that of ma # 3-lag 2-equation 4MA VARMA ar3 = np.random.randn(3, 2, 2) ma4 = np.random.randn(4, 2, 2) wold.VARParams(ar3, ma4) with pytest.raises(ValueError): # pass ma that suggests too few equations wold.VARParams(ar3, ma4[:, :-1, :-1]) with pytest.raises(ValueError): # pass ma with internally-inconsistent shape wold.VARParams(ar3, ma4[:, :-1, :])
def test_invalid_shapes_var(self): # 3-lag 2-equation VAR ar3 = np.random.randn(3, 2, 2) with pytest.raises(ValueError): # too few dimensions wold.VARParams(ar3[:, :, 0]) with pytest.raises(ValueError): # shape[1] != shape[2] wold.VARParams(ar3[:, :, :-1]) with pytest.raises(ValueError): # len(shape) < 3 wold.VARParams(ar3[:, :, 0])
def test_invalid_intercept_var(self): # 3-lag 2-equation VAR ar3 = np.random.randn(3, 2, 2) intercept = np.array([1, 2]) # smoke tests for valid paramaters wold.VARParams(ar3) wold.VARParams(ar3, intercept=intercept) with pytest.raises(ValueError): wold.VARParams(ar3, intercept=intercept.reshape(2, 1)) with pytest.raises(ValueError): wold.VARParams(ar3, intercept=intercept.reshape(1, 2)) with pytest.raises(ValueError): wold.VARParams(ar3, intercept=np.array(4))
def setup_class(cls): ar = [[[1., 2, 3], [0, 1., 4], [0, 0, 1.]]] # Choose AR params to be not-stationary arparams = np.array(ar) ma = [[[0, .1, -1], [.2, -.3, 0], [0.1, 2.1, -0.4]]] maparams = np.array(ma) cls.varma = wold.VARParams(arparams, maparams)
def setup_class(cls): # AR Process that we'll treat as a VAR ar = [1, -.25] # Note that this induces an # AR Polynomial L^0 - L^1 + .25 L^2 --> (1-.5L)**2 arparams = np.array(ar) ma = [] maparams = np.array(ma) cls.varma = wold.VARParams(arparams, maparams)
def test_equiv_construction(self): # Test that passing np.array([]) or None as maparams is equivalent varma = self.varma other = wold.VARParams(varma.arcoefs, None) assert (other.macoefs == varma.macoefs).all()