Beispiel #1
0
 def test_sigmoid(self):
     # pylint: disable=no-self-use
     # pylint: disable=protected-access
     """
     Tests Sigmoid Calculation.
     """
     # Initialize FCORN.
     fcorn5 = FCORN(window=1, rho=0.5, lambd=10)
     sig = fcorn5._sigmoid(0.0)
     np.testing.assert_almost_equal(sig, 0.5)
Beispiel #2
0
 def test_fcorn_solution1(self):
     """
     Test the calculation of FCORN for edge case that activation function is 0.
     """
     # Initialize FCORN.
     fcorn6 = FCORN(window=1, rho=0.5, lambd=10)
     # Allocates asset prices to FCORN.
     fcorn6.allocate(self.data, resample_by='Y')
     # Create np.array of all_weights.
     all_weights = np.array(fcorn6.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)
Beispiel #3
0
    def test_fcorn_rho_error(self):
        """
        Tests ValueError if rho is less than -1 or more than 1.
        """
        # Initialize FCORN.
        fcorn3 = FCORN(window=2, rho=-2, lambd=4)
        with self.assertRaises(ValueError):
            # Running allocate will raise ValueError.
            fcorn3.allocate(self.data)

        # Initialize FCORN.
        fcorn4 = FCORN(window=2, rho=2, lambd=8)
        with self.assertRaises(ValueError):
            # Running allocate will raise ValueError.
            fcorn4.allocate(self.data)
Beispiel #4
0
    def test_fcorn_window_error(self):
        """
        Tests ValueError if window is not an integer or less than 1.
        """
        # Initialize FCORN.
        fcorn1 = FCORN(window=2.5, rho=0.5, lambd=1)
        with self.assertRaises(ValueError):
            # Running allocate will raise ValueError.
            fcorn1.allocate(self.data)

        # Initialize FCORN.
        fcorn2 = FCORN(window=0, rho=0.5, lambd=2)
        with self.assertRaises(ValueError):
            # Running allocate will raise ValueError.
            fcorn2.allocate(self.data)
Beispiel #5
0
    def _generate_experts(self):
        """
        Generates window * rho experts from window of [1, w], rho of [0, (rho - 1) / rho], and
        lambd of [1, 10 ** (lambd-1)].
        """
        # Initialize expert parameters.
        self.expert_params = np.zeros((self.number_of_experts, 3))
        # Pointer to iterate through parameter locations.
        pointer = 0
        # Window from 1 to self.window.
        for n_window in range(self.window):
            # Rho from 0 to (rho - 1)/rho.
            for n_rho in range(self.rho):
                for n_lambd in range(self.lambd):
                    # Assign experts with parameters (n_window + 1, n_rho/rho, 10 ** n_lambd).
                    self.expert_params[pointer] = [
                        n_window + 1, n_rho / self.rho, 10**n_lambd
                    ]
                    pointer += 1

        for exp in range(self.number_of_experts):
            param = self.expert_params[exp]
            self.experts.append(FCORN(int(param[0]), param[1], param[2]))