Example #1
0
    def test_resets_data(self):
        """Tests if the data is reset properly.
        """
        from_date = datetime(2016, 1, 1)
        to_date = datetime(2016, 3, 1)
        stock_names = ["STOCK_1"]
        value = 100
        mean = 0.05
        stdev = 0.025
        dependency = GeneratedStockData(evaluation_functions=[str(value)])
        data = RandomizedStockData(dependencies=["stock_data"],
                                   mean=mean,
                                   stdev=stdev)
        dependency.prepare_data(from_date, to_date, stock_names, [])
        data.prepare_data(from_date, to_date, stock_names, [dependency])

        data_before_reset = data.data["STOCK_1"].copy()

        self.assertTrue(data.ready)
        data.reset([True])
        self.assertFalse(data.ready)

        data.prepare_data(from_date, to_date, stock_names, [dependency])
        data_after_reset = data.data["STOCK_1"]
        self.assertFalse(data_before_reset.equals(data_after_reset))
 def test_prepare_data(self):
     """Tests if the data is prepared properly.
     """
     from_date = datetime(2016, 1, 1)
     to_date = datetime(2016, 2, 1)
     stock_names = ["STOCK_1", "STOCK_2"]
     data = GeneratedStockData(evaluation_functions=["100", "200"])
     data.prepare_data(from_date, to_date, stock_names, [])
     self.assertTrue(data.ready)
     self.assertTrue((stock_names == data.data.columns.tolist()))
     self.assertEqual(100, data[from_date][0])
     self.assertEqual(200, data[from_date][1])
 def test_resets_data(self):
     """Tests if the data is reset properly.
     """
     from_date = datetime(2016, 1, 1)
     to_date = datetime(2020, 1, 1)
     stock_names = ["STOCK_1"]
     dependency = GeneratedStockData(evaluation_functions=["100"])
     data = RunningAverageAnalysis(dependencies=["stock_data"])
     dependency.prepare_data(from_date, to_date, stock_names, [])
     data.prepare_data(from_date, to_date, stock_names, [dependency])
     self.assertTrue(data.ready)
     data.reset([True])
     self.assertTrue(data.ready)
 def test_reset(self):
     """Tests if the data is reset properly.
     """
     from_date = datetime(2016, 1, 1)
     to_date = datetime(2016, 1, 3)
     stock_names = ["STOCK_1"]
     value = 100
     dependency = GeneratedStockData(evaluation_functions=[str(value)])
     data = RelativeStockData(dependencies=["stock_data"])
     dependency.prepare_data(from_date, to_date, stock_names, [])
     data.prepare_data(from_date, to_date, stock_names, [dependency])
     data.reset([True])
     self.assertTrue(data.ready)
     data.reset([False])
     self.assertFalse(data.ready)
 def test_prepare_data(self):
     """Tests if the data is prepared properly.
     """
     from_date = datetime(2016, 1, 1)
     to_date = datetime(2016, 1, 3)
     stock_names = ["STOCK_1"]
     value = 100
     dependency = GeneratedStockData(evaluation_functions=[str(value)])
     data = RelativeStockData(dependencies=["stock_data"])
     dependency.prepare_data(from_date, to_date, stock_names, [])
     dependency.data.iloc[1] = 200
     data.prepare_data(from_date, to_date, stock_names, [dependency])
     self.assertTrue(data.ready)
     self.assertTrue((stock_names == data.data.columns.tolist()))
     self.assertEqual(1, data.data.iloc[0].item())
     self.assertEqual(-0.5, data[to_date].item())
    def test_prepare_data(self):
        """Tests if the data is prepared properly.
        """
        from_date = datetime(2016, 1, 1)
        to_date = datetime(2016, 2, 1)
        num_days = 5
        stock_names = ["STOCK_1", "STOCK_2"]
        expected_columns = [
            "ra_5_stock_data_STOCK_1", "ra_5_stock_data_STOCK_2"
        ]

        dependency = GeneratedStockData(evaluation_functions=["100"])
        data = RunningAverageAnalysis(dependencies=["stock_data"],
                                      num_days=num_days)
        dependency.prepare_data(from_date, to_date, stock_names, [])
        data.prepare_data(from_date, to_date, stock_names, [dependency])

        self.assertTrue(data.ready)
        self.assertTrue((expected_columns == data.data.columns.tolist()))
        self.assertEqual(len(dependency) - num_days + 1, len(data))
        self.assertEqual(100, data[to_date][0])
Example #7
0
 def test_prepare_data(self):
     """Tests if the data is prepared properly.
     """
     from_date = datetime(2016, 1, 1)
     to_date = datetime(2020, 1, 1)
     stock_names = ["STOCK_1"]
     value = 100
     mean = 0.05
     stdev = 0.025
     dependency = GeneratedStockData(evaluation_functions=[str(value)])
     data = RandomizedStockData(dependencies=["stock_data"],
                                mean=mean,
                                stdev=stdev)
     dependency.prepare_data(from_date, to_date, stock_names, [])
     data.prepare_data(from_date, to_date, stock_names, [dependency])
     self.assertTrue(data.ready)
     self.assertTrue((stock_names == data.data.columns.tolist()))
     self.assertTrue(
         np.isclose(value * (1 + mean),
                    data.data["STOCK_1"].mean(),
                    rtol=0.1))
     self.assertTrue(
         np.isclose(value * stdev, data.data["STOCK_1"].std(), rtol=0.1))
 def test_resets_data(self):
     """Tests if the data is reset properly.
     """
     from_date = datetime(2016, 1, 1)
     to_date = datetime(2016, 2, 1)
     stock_names = ["STOCK_1", "STOCK_2"]
     data = GeneratedStockData(evaluation_functions=["100"])
     data.prepare_data(from_date, to_date, stock_names, [])
     self.assertTrue(data.ready)
     data.reset([])
     self.assertTrue(data.ready)
    def test_prepare_data(self):
        """Tests if the data is prepared properly.
        """
        from_date = datetime(2016, 1, 1)
        to_date = datetime(2016, 1, 1)
        to_date_2 = datetime(2016, 1, 2)
        stock_names = ["STOCK_1"]

        generated_data_1 = GeneratedStockData(evaluation_functions=["1"])
        generated_data_2 = GeneratedStockData(evaluation_functions=["2"])
        dependencies = [generated_data_1, generated_data_2]

        generated_data_1.prepare_data(from_date, to_date, stock_names, [])
        generated_data_2.prepare_data(from_date, to_date_2, stock_names, [])

        for operator in ["ge", "gt", "eq"]:
            comparator = ComparatorAnalysis(dependencies=["x", "x"], operator=operator)
            comparator.prepare_data(from_date, to_date, stock_names, dependencies)
            self.assertEqual(0, comparator[from_date].item())

        for operator in ["lt", "le", "ne"]:
            comparator = ComparatorAnalysis(dependencies=["x", "x"], operator=operator)
            comparator.prepare_data(from_date, to_date, stock_names, dependencies)
            self.assertEqual(1, comparator[from_date].item())
 def test_initializes(self):
     """Tests if initializes properly.
     """
     data = GeneratedStockData(evaluation_functions=["100", "200"])
     self.assertFalse(data.visible)
 def test_requires_evaluation_functions(self):
     """Tests if raises exception when no evaluation functions are provided.
     """
     with self.assertRaises(ValueError):
         _ = GeneratedStockData()