def test_pamr_agg_error(self): """ Tests ValueError if aggressiveness is less than 0. """ # Initialize PAMR. pamr4 = PAMR(optimization_method=2, epsilon=0.5, agg=-5) with self.assertRaises(ValueError): # Running allocate will raise ValueError. pamr4.allocate(self.data)
def test_pamr_epsilon_error(self): """ Tests ValueError if epsilon is less than 0. """ # Initialize PAMR. pamr3 = PAMR(optimization_method=2, epsilon=-1, agg=10) with self.assertRaises(ValueError): # Running allocate will raise ValueError. pamr3.allocate(self.data)
def test_pamr_method_error(self): """ Tests ValueError if optimization method is not 0, 1, or 2. """ # Initialize PAMR. pamr5 = PAMR(optimization_method=5, epsilon=0.5, agg=10) with self.assertRaises(ValueError): # Running allocate will raise ValueError. pamr5.allocate(self.data)
def test_pamr2_solution(self): """ Test the calculation of passive aggressive mean reversion with the PAMR-2 optimization method """ # Initialize PAMR-2. pamr2 = PAMR(optimization_method=2, epsilon=0.5, agg=10) # Allocates asset prices to PAMR. pamr2.allocate(self.data, resample_by='M') # Create np.array of all_weights. all_weights = np.array(pamr2.all_weights) # Check if all weights sum to 1. for i in range(all_weights.shape[0]): weights = all_weights[i] assert (weights >= 0).all() assert len(weights) == self.data.shape[1] np.testing.assert_almost_equal(np.sum(weights), 1)