def test_wrong_run_input_value_error_raise(self):
     """
     Tests ValueError raise when neither pd.DataFrame nor path to csv file are passed to function call
     """
     with self.assertRaises(ValueError):
         bars = ds.StandardBars(metric='cum_dollar_value')
         bars.run(None)
Ejemplo n.º 2
0
    def test_list_as_run_input(self):
        """
        Tests that data generated with csv file and list yield the same result
        """
        threshold = 100000
        tick_data = pd.read_csv(self.path)
        tick_data['Date and Time'] = pd.to_datetime(tick_data['Date and Time'])

        db1 = ds.get_dollar_bars(self.path, threshold=threshold, batch_size=1000, verbose=False)
        ds.get_dollar_bars(self.path, threshold=threshold, batch_size=50, verbose=False,
                           to_csv=True, output_path='test.csv')
        db2 = pd.read_csv('test.csv')
        db2['date_time'] = pd.to_datetime(db2.date_time)

        bars = ds.StandardBars(metric='cum_dollar_value', threshold=threshold)
        cols = ['date_time', 'tick_num', 'open', 'high', 'low', 'close', 'volume', 'cum_buy_volume', 'cum_ticks',
                'cum_dollar_value']

        data = tick_data.values.tolist()
        final_bars = bars.run(data)
        db3 = pd.DataFrame(final_bars, columns=cols)

        # Assert diff batch sizes have same number of bars
        self.assertTrue(db1.shape == db2.shape)
        self.assertTrue(db1.shape == db3.shape)

        # Assert same values
        self.assertTrue(np.all(db1.values == db2.values))
        self.assertTrue(np.all(db1.values == db3.values))