Beispiel #1
0
class TestDataset(unittest.TestCase):
    def setUp(self):
        root_dir = os.path.dirname(os.path.realpath(__file__))
        data_dir = os.path.join(root_dir, "data")
        self.reader = CsvReader(data_dir)

    def test_read_spy(self):
        dataset = self.reader.read_dataset(["SPY"], [ColumnName.ADJCLOSE])
        self.assertEqual(dataset.column(ColumnName.ADJCLOSE).shape[0], 50)
        self.assertEqual(dataset.column(ColumnName.ADJCLOSE).shape[1], 1)

    def test_read_goog(self):
        dataset = self.reader.read_dataset(["GOOG"], [ColumnName.ADJCLOSE])
        self.assertEqual(dataset.column(ColumnName.ADJCLOSE).shape[0], 30)
        self.assertEqual(dataset.column(ColumnName.ADJCLOSE).shape[1], 1)

    def test_read_gld(self):
        dataset = self.reader.read_dataset(["GLD"], [ColumnName.ADJCLOSE])
        self.assertEqual(dataset.column(ColumnName.ADJCLOSE).shape[0], 70)
        self.assertEqual(dataset.column(ColumnName.ADJCLOSE).shape[1], 1)

    def test_read_all(self):
        dataset = self.reader.read_dataset(["SPY", "GOOG", "GLD"],
                                           [ColumnName.ADJCLOSE])
        self.assertEqual(dataset.column(ColumnName.ADJCLOSE).shape[0], 70)
        self.assertEqual(dataset.column(ColumnName.ADJCLOSE).shape[1], 3)

    def test_read_multycol(self):
        dataset = self.reader.read_dataset(
            ["SPY"], [ColumnName.CLOSE, ColumnName.ADJCLOSE])
        self.assertEqual(len(dataset.columns), 2)
Beispiel #2
0
class TestColumn(unittest.TestCase):
    def setUp(self):
        root_dir = os.path.dirname(os.path.realpath(__file__))
        data_dir = os.path.join(root_dir, "data")
        self.reader = CsvReader(data_dir)

    def test_read_spy(self):
        df = self.reader.read_column(["SPY"], ColumnName.ADJCLOSE)
        self.assertEqual(df.shape[0], 50)
        self.assertEqual(df.shape[1], 1)

    def test_read_goog(self):
        df = self.reader.read_column(["GOOG"], ColumnName.ADJCLOSE)
        self.assertEqual(df.shape[0], 30)
        self.assertEqual(df.shape[1], 1)

    def test_read_gld(self):
        df = self.reader.read_column(["GLD"], ColumnName.ADJCLOSE)
        self.assertEqual(df.shape[0], 70)
        self.assertEqual(df.shape[1], 1)

    def test_read_all(self):
        df = self.reader.read_column(["SPY", "GOOG", "GLD"],
                                     ColumnName.ADJCLOSE)
        self.assertEqual(df.shape[0], 70)
        self.assertEqual(df.shape[1], 3)
Beispiel #3
0
 def setUp(self):
     root_dir = os.path.dirname(os.path.realpath(__file__))
     data_dir = os.path.join(root_dir, "data")
     self.dfs = [
         CsvReader(data_dir).read_column(["SPY"], ColumnName.ADJCLOSE),
         CsvReader(data_dir).read_column(["GOOG"], ColumnName.ADJCLOSE)
     ]
Beispiel #4
0
class TestMerge(unittest.TestCase):
    def setUp(self):
        root_dir = os.path.dirname(os.path.realpath(__file__))
        data_dir = os.path.join(root_dir, "data")
        self.reader = CsvReader(data_dir)

    def test_merge_tickers(self):
        df_a = self.reader.read_column(["GOOG"], ColumnName.ADJCLOSE)
        df_b = self.reader.read_column(["GLD"], ColumnName.ADJCLOSE)
        df_c = Merge().process(df_a, df_b)
        self.assertListEqual(df_c.columns.tolist(), ["GOOG", "GLD"])
Beispiel #5
0
class TestNormalize(unittest.TestCase):
    def setUp(self):
        root_dir = os.path.dirname(os.path.realpath(__file__))
        data_dir = os.path.join(root_dir, "data")
        self.df = CsvReader(data_dir).read_column(["SPY"], ColumnName.ADJCLOSE)

    def test_normalize(self):
        normalized_df = Normalize().process(self.df)
        self.assertEqual(normalized_df.max().tolist(),
                         (self.df.max() / self.df.iloc[0]).tolist())

    def test_indicator(self):
        normalized_df = NormalizeIndicator().process(self.df)
        self.assertEqual(normalized_df.max().tolist(),
                         ((self.df.max() - self.df.mean()) /
                          self.df.std()).tolist())
Beispiel #6
0
class TestBaseline(unittest.TestCase):
    def setUp(self):
        root_dir = os.path.dirname(os.path.realpath(__file__))
        data_dir = os.path.join(root_dir, "data")
        self.df = CsvReader(data_dir).read_column(["SPY", "GOOG", "GLD"],
                                                  ColumnName.ADJCLOSE)

    def test_fill(self):
        self.assertEqual(self.df.isnull().sum().sum(), 60)
        filled_df = FillMissing().process(self.df)
        self.assertEqual(filled_df.isnull().sum().sum(), 0)
Beispiel #7
0
 def setUp(self):
     root_dir = os.path.dirname(os.path.realpath(__file__))
     data_dir = os.path.join(root_dir, "data")
     self.reader = CsvReader(data_dir)