Esempio n. 1
0
    def test_simple_beta_input_validation(self):
        with self.assertRaises(TypeError) as e:
            SimpleBeta(
                target="SPY",
                regression_length=100,
                allowed_missing_percentage=0.5,
            )
        result = str(e.exception)
        expected = (r"SimpleBeta\(\) expected a value of type"
                    " .*Asset for argument 'target',"
                    " but got str instead.")
        self.assertRegexpMatches(result, expected)

        with self.assertRaises(ValueError) as e:
            SimpleBeta(
                target=self.my_asset,
                regression_length=1,
                allowed_missing_percentage=0.5,
            )
        result = str(e.exception)
        expected = ("SimpleBeta() expected a value greater than or equal to 3"
                    " for argument 'regression_length', but got 1 instead.")
        self.assertEqual(result, expected)

        with self.assertRaises(ValueError) as e:
            SimpleBeta(
                target=self.my_asset,
                regression_length=100,
                allowed_missing_percentage=50,
            )
        result = str(e.exception)
        expected = (
            "SimpleBeta() expected a value inclusively between 0.0 and 1.0 "
            "for argument 'allowed_missing_percentage', but got 50 instead.")
        self.assertEqual(result, expected)
Esempio n. 2
0
    def test_simple_beta_input_validation(self):
        expected = ("SimpleBeta() expected a value of type"
                    " Asset for argument 'target',"
                    " but got str instead.")
        with pytest.raises(TypeError, match=re.escape(expected)):
            SimpleBeta(
                target="SPY",
                regression_length=100,
                allowed_missing_percentage=0.5,
            )

        expected = ("SimpleBeta() expected a value greater than or equal to 3"
                    " for argument 'regression_length', but got 1 instead.")
        with pytest.raises(ValueError, match=re.escape(expected)):
            SimpleBeta(
                target=self.my_asset,
                regression_length=1,
                allowed_missing_percentage=0.5,
            )

        expected = (
            "SimpleBeta() expected a value inclusively between 0.0 and 1.0 "
            "for argument 'allowed_missing_percentage', but got 50 instead.")
        with pytest.raises(ValueError, match=re.escape(expected)):
            SimpleBeta(
                target=self.my_asset,
                regression_length=100,
                allowed_missing_percentage=50,
            )
Esempio n. 3
0
 def test_simple_beta_graph_repr(self):
     beta = SimpleBeta(
         target=self.my_asset,
         regression_length=50,
         allowed_missing_percentage=0.5,
     )
     result = beta.graph_repr()
     expected = "SimpleBeta('A', 50, 25)".format(self.my_asset)
     self.assertEqual(result, expected)
 def test_simple_beta_short_repr(self):
     beta = SimpleBeta(
         target=self.my_asset,
         regression_length=50,
         allowed_missing_percentage=0.5,
     )
     result = beta.short_repr()
     expected = "SimpleBeta('A', 50, 25)".format(self.my_asset)
     self.assertEqual(result, expected)
Esempio n. 5
0
 def test_simple_beta_target(self):
     beta = SimpleBeta(
         target=self.my_asset,
         regression_length=50,
         allowed_missing_percentage=0.5,
     )
     self.assertIs(beta.target, self.my_asset)
Esempio n. 6
0
 def test_simple_beta_allowed_missing_calculation(self):
     for percentage, expected in [(0.651, 65), (0.659, 65), (0.66, 66),
                                  (0.0, 0), (1.0, 100)]:
         beta = SimpleBeta(
             target=self.my_asset,
             regression_length=100,
             allowed_missing_percentage=percentage,
         )
         self.assertEqual(beta.params['allowed_missing_count'], expected)
Esempio n. 7
0
 def test_simple_beta_repr(self):
     beta = SimpleBeta(
         target=self.my_asset,
         regression_length=50,
         allowed_missing_percentage=0.5,
     )
     result = repr(beta)
     expected = "SimpleBeta({}, length=50, allowed_missing=25)".format(
         self.my_asset, )
     self.assertEqual(result, expected)
Esempio n. 8
0
 def test_simple_beta_matches_regression(self):
     run_pipeline = self.run_pipeline
     simple_beta = SimpleBeta(target=self.my_asset, regression_length=10)
     complex_beta = RollingLinearRegressionOfReturns(
         target=self.my_asset,
         returns_length=2,
         regression_length=10,
     ).beta
     pipe = Pipeline({'simple': simple_beta, 'complex': complex_beta})
     results = run_pipeline(
         pipe,
         self.pipeline_start_date,
         self.pipeline_end_date,
     )
     assert_equal(results['simple'], results['complex'], check_names=False)