Exemplo n.º 1
0
    def test_calculate_turnover(self):
        algorithm = Algorithm()

        #simple weights - no change in weights
        current_weights = np.array([0.5, 0.5])
        last_weights = np.array([0.5, 0.5])
        current_individual_returns = np.array([1.1, 1.1])
        result = algorithm.calculate_turnover2(current_weights,
                                               last_weights,
                                               current_individual_returns,
                                               iteration=999)
        self.assertEqual(result, 0.0)

        #simple weights - change with same returns
        current_weights = np.array([0.5, 0.5])
        last_weights = np.array([0.6, 0.4])
        current_individual_returns = np.array([1.0, 1.0])
        result = algorithm.calculate_turnover2(current_weights,
                                               last_weights,
                                               current_individual_returns,
                                               iteration=999)
        self.assertAlmostEqual(result, 0.2, 3)

        #simple weights - change with same returns
        current_weights = np.array([0.5, 0.5])
        last_weights = np.array([0.6, 0.4])
        current_individual_returns = np.array([1.0, 1.0])
        result = algorithm.calculate_turnover2(current_weights,
                                               last_weights,
                                               current_individual_returns,
                                               iteration=999)
        self.assertAlmostEqual(result, 0.2, 3)

        #simple weights - no change but different returns
        current_weights = np.array([0.5, 0.5])
        last_weights = np.array([0.5, 0.5])
        current_individual_returns = np.array([1.2, 1.0])
        result = algorithm.calculate_turnover2(current_weights,
                                               last_weights,
                                               current_individual_returns,
                                               iteration=999)
        self.assertAlmostEqual(result, 0.1, 3)
Exemplo n.º 2
0
    def test_calculate_turnover_negative_weights(self):
        algorithm = Algorithm()

        #simple weights - no change in weights
        current_weights = np.array([0.6, -0.3, 0.4])
        last_weights = np.array([0.6, -0.3, 0.4])
        current_individual_returns = np.array([1.1, 1.1, 1.0])
        result = algorithm.calculate_turnover2(current_weights,
                                               last_weights,
                                               current_individual_returns,
                                               iteration=999)
        self.assertAlmostEqual(result, 0.06, 3)