Пример #1
0
 def test_yahoo_wrong_use(self):
     """Yahoo! wrong use test"""
     yahoo = YahooDataProvider(
         tickers=["AEO", "ABBY"],
         start=datetime.datetime(2018, 1, 1),
         end=datetime.datetime(2018, 12, 31),
     )
     # Now, the .run() method is expected, which does the actual data loading
     with self.subTest("test YahooDataProvider get_covariance_matrix"):
         self.assertRaises(QiskitFinanceError, yahoo.get_covariance_matrix)
     with self.subTest("test YahooDataProvider get_similarity_matrix"):
         self.assertRaises(QiskitFinanceError, yahoo.get_similarity_matrix)
Пример #2
0
 def test_yahoo(self):
     """ Yahoo data test """
     try:
         yahoo = YahooDataProvider(
             tickers=["AEO", "ABBY"],
             start=datetime.datetime(2018, 1, 1),
             end=datetime.datetime(2018, 12, 31)
         )
         yahoo.run()
         similarity = np.array([
             [1.00000000e+00, 8.44268222e-05],
             [8.44268222e-05, 1.00000000e+00]
         ])
         covariance = np.array(
             [[7.174e+0, -1.671e-04],
              [-1.671e-04, 1.199e-06]])
         with self.subTest('test YahooDataProvider get_covariance_matrix'):
             np.testing.assert_array_almost_equal(yahoo.get_covariance_matrix(),
                                                  covariance, decimal=3)
         with self.subTest('test YahooDataProvider get_similarity_matrix'):
             np.testing.assert_array_almost_equal(yahoo.get_similarity_matrix(),
                                                  similarity, decimal=3)
     except MissingOptionalLibraryError as ex:
         self.skipTest(str(ex))
     except QiskitFinanceError as ex:
         self.skipTest("Test of YahooDataProvider skipped {}".format(str(ex)))
Пример #3
0
 def test_yahoo_wrong_use(self):
     """ Yahoo! wrong use test """
     try:
         yahoo = YahooDataProvider(
             tickers=["AEO", "ABBY"],
             start=datetime.datetime(2018, 1, 1),
             end=datetime.datetime(2018, 12, 31)
         )
         # Now, the .run() method is expected, which does the actual data loading
         with self.subTest('test YahooDataProvider get_covariance_matrix'):
             self.assertRaises(QiskitFinanceError, yahoo.get_covariance_matrix)
         with self.subTest('test YahooDataProvider get_similarity_matrix'):
             self.assertRaises(QiskitFinanceError, yahoo.get_similarity_matrix)
     except MissingOptionalLibraryError as ex:
         self.skipTest(str(ex))
Пример #4
0
 def test_yahoo(self, tickers, covariance, similarity):
     """Yahoo data test"""
     yahoo = YahooDataProvider(
         tickers=tickers,
         start=datetime.datetime(2018, 1, 1),
         end=datetime.datetime(2018, 12, 31),
     )
     try:
         yahoo.run()
         with self.subTest("test YahooDataProvider get_covariance_matrix"):
             np.testing.assert_array_almost_equal(
                 yahoo.get_covariance_matrix(),
                 np.array(covariance),
                 decimal=0)
         with self.subTest("test YahooDataProvider get_similarity_matrix"):
             np.testing.assert_array_almost_equal(
                 yahoo.get_similarity_matrix(),
                 np.array(similarity),
                 decimal=1)
     except QiskitFinanceError as ex:
         self.skipTest(f"Test of YahooDataProvider skipped {str(ex)}")