Пример #1
0
 def test_scorn_k_solution(self):
     """
     Test the calculation of SCORN-K.
     """
     # Initialize SCORN-K.
     scorn_k = SCORNK(window=2, rho=2, k=1)
     # Allocates asset prices to SCORN-K.
     scorn_k.allocate(self.data, resample_by='M')
     # Create np.array of all_weights.
     all_weights = np.array(scorn_k.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)
Пример #2
0
    def test_scorn_k_rho_error(self):
        """
        Tests ValueError if rho is not an integer or less than 1.
        """
        # Initialize SCORN-K.
        scorn_k3 = SCORNK(window=2, rho=2.5, k=1)
        with self.assertRaises(ValueError):
            # Running allocate will raise ValueError.
            scorn_k3.allocate(self.data)

        # Initialize SCORN-K.
        scorn_k4 = SCORNK(window=2, rho=0, k=1)
        with self.assertRaises(ValueError):
            # Running allocate will raise ValueError.
            scorn_k4.allocate(self.data)
Пример #3
0
    def test_scorn_k_window_error(self):
        """
        Tests ValueError if window is not an integer or less than 1.
        """
        # Initialize SCORN-K.
        scorn_k1 = SCORNK(window=2.5, rho=2, k=1)
        with self.assertRaises(ValueError):
            # Running allocate will raise ValueError.
            scorn_k1.allocate(self.data)

        # Initialize SCORN-K.
        scorn_k2 = SCORNK(window=0, rho=2, k=1)
        with self.assertRaises(ValueError):
            # Running allocate will raise ValueError.
            scorn_k2.allocate(self.data)
Пример #4
0
    def test_scorn_k_k_error(self):
        """
        Tests ValueError if k is greater than window * rho, greater than 1, or an integer.
        """
        # Initialize SCORN-K.
        scorn_k5 = SCORNK(window=2, rho=2, k=5)
        with self.assertRaises(ValueError):
            # Running allocate will raise ValueError.
            scorn_k5.allocate(self.data)

        # Initialize SCORN-K.
        scorn_k6 = SCORNK(window=2, rho=2, k=1.5)
        with self.assertRaises(ValueError):
            # Running allocate will raise ValueError.
            scorn_k6.allocate(self.data)

        # Initialize SCORN-K.
        scorn_k7 = SCORNK(window=2, rho=2, k=0)
        with self.assertRaises(ValueError):
            # Running allocate will raise ValueError.
            scorn_k7.allocate(self.data)