Exemplo n.º 1
0
 def test_random_wrong_use(self):
     """ Random wrong use test """
     try:
         rnd = RandomDataProvider(seed=1)
         # Now, the .run() method is expected, which does the actual data loading
         # (and can take seconds or minutes,
         # depending on the data volumes, hence not ok in the constructor)
         with self.subTest('test RandomDataProvider get_covariance_matrix'):
             self.assertRaises(QiskitFinanceError,
                               rnd.get_covariance_matrix)
         with self.subTest('test RandomDataProvider get_similarity_matrix'):
             self.assertRaises(QiskitFinanceError,
                               rnd.get_similarity_matrix)
         wiki = WikipediaDataProvider(token=self._quandl_token,
                                      tickers=["GOOG", "AAPL"],
                                      start=datetime.datetime(2016, 1, 1),
                                      end=datetime.datetime(2016, 1, 30))
         # Now, the .run() method is expected, which does the actual data loading
         with self.subTest(
                 'test WikipediaDataProvider get_covariance_matrix'):
             self.assertRaises(QiskitFinanceError,
                               wiki.get_covariance_matrix)
         with self.subTest(
                 'test WikipediaDataProvider get_similarity_matrix'):
             self.assertRaises(QiskitFinanceError,
                               wiki.get_similarity_matrix)
     except MissingOptionalLibraryError as ex:
         self.skipTest(str(ex))
Exemplo n.º 2
0
 def test_wikipedia(self):
     """ wikipedia test """
     try:
         wiki = WikipediaDataProvider(
             token=self._quandl_token,
             tickers=["GOOG", "AAPL"],
             start=datetime.datetime(2016, 1, 1),
             end=datetime.datetime(2016, 1, 30)
         )
         wiki.run()
         similarity = np.array([
             [1.00000000e+00, 8.44268222e-05],
             [8.44268222e-05, 1.00000000e+00]
         ])
         covariance = np.array([
             [269.60118129, 25.42252332],
             [25.42252332, 7.86304499]
         ])
         with self.subTest('test WikipediaDataProvider get_covariance_matrix'):
             np.testing.assert_array_almost_equal(wiki.get_covariance_matrix(),
                                                  covariance, decimal=3)
         with self.subTest('test WikipediaDataProvider get_similarity_matrix'):
             np.testing.assert_array_almost_equal(wiki.get_similarity_matrix(),
                                                  similarity, decimal=3)
     except MissingOptionalLibraryError as ex:
         self.skipTest(str(ex))
     except QiskitFinanceError as ex:
         self.skipTest("Test of WikipediaDataProvider skipped: {}".format(str(ex)))