def test_save_stock_datetime(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") temp = get_temp_folder(__file__, "temp_save_stock_datetime") cache = temp stock = StockPrices(TestStockFileDatetime.tick, use_dtime=True, folder=cache, end=datetime.datetime(2014, 1, 15), url=TestStockFileDatetime.source) file = os.path.join(cache, "save.txt") if os.path.exists(file): os.remove(file) stock.to_csv(file) self.assertTrue(os.path.exists(file)) stock2 = StockPrices(file, sep="\t", use_dtime=True) self.assertEqual(stock.dataframe.shape, stock2.dataframe.shape) df = stock2.dataframe file = os.path.join(cache, "out_excel.xlsx") if os.path.exists(file): os.remove(file) df.to_excel(file) self.assertTrue(os.path.exists(file))
def test_save_stock_google(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") cache = os.path.abspath(os.path.split(__file__)[0]) cache = os.path.join(cache, "temp_cache_file_google") name = os.path.join(cache, "NASDAQ_GOOG.2000-01-03.2014-01-15.txt") if os.path.exists(name): os.remove(name) stock = StockPrices( "NASDAQ:GOOG", url="google", folder=cache, end=datetime.datetime( 2014, 1, 15)) file = os.path.join(cache, "save.txt") if os.path.exists(file): os.remove(file) stock.to_csv(file) assert os.path.exists(file) stock2 = StockPrices(file, sep="\t") assert stock.dataframe.shape == stock2.dataframe.shape df = stock2.dataframe file = os.path.join(cache, "out_excel.xlsx") if os.path.exists(file): os.remove(file) df.to_excel(file) assert os.path.exists(file)
def test_save_stock_google(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") cache = os.path.abspath(os.path.split(__file__)[0]) cache = os.path.join(cache, "temp_cache_file_google") name = os.path.join(cache, "NASDAQ_GOOG.2000-01-03.2014-01-15.txt") if os.path.exists(name): os.remove(name) stock = StockPrices("NASDAQ:GOOG", url="google", folder=cache, end=datetime.datetime(2014, 1, 15)) file = os.path.join(cache, "save.txt") if os.path.exists(file): os.remove(file) stock.to_csv(file) assert os.path.exists(file) stock2 = StockPrices(file, sep="\t") assert stock.dataframe.shape == stock2.dataframe.shape df = stock2.dataframe file = os.path.join(cache, "out_excel.xlsx") if os.path.exists(file): os.remove(file) df.to_excel(file) assert os.path.exists(file)
def test_save_stock_yahoo_new(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") temp = get_temp_folder(__file__, "temp_cache_file_yahoo") cache = temp stock = StockPrices("AAPL", folder=cache, url="yahoo_new", end=datetime.datetime(2014, 1, 15)) file = os.path.join(cache, "save.txt") if os.path.exists(file): os.remove(file) stock.to_csv(file) self.assertTrue(os.path.exists(file)) stock2 = StockPrices(file, sep="\t") self.assertEqual(stock.dataframe.shape, stock2.dataframe.shape) df = stock2.dataframe file = os.path.join(cache, "out_excel.xlsx") if os.path.exists(file): os.remove(file) df.to_excel(file) self.assertTrue(os.path.exists(file))
def test_save_stock_quandl(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") temp = get_temp_folder(__file__, "temp_cache_file_quandl") cache = temp try: stock = StockPrices("EURONEXT/BNP", url="quandl", folder=cache, end=datetime.datetime(2017, 1, 15)) except LimitExceededError: warnings.warn( "[test_save_stock_quandl] reached quandl free quota. Stop test." ) return file = os.path.join(cache, "save.txt") if os.path.exists(file): os.remove(file) stock.to_csv(file) self.assertTrue(os.path.exists(file)) stock2 = StockPrices(file, sep="\t") self.assertEqual(stock.dataframe.shape, stock2.dataframe.shape) df = stock2.dataframe file = os.path.join(cache, "out_excel.xlsx") if os.path.exists(file): os.remove(file) df.to_excel(file) self.assertTrue(os.path.exists(file))
def test_save_stock_google(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") temp = get_temp_folder(__file__, "temp_cache_file_google") cache = temp try: stock = StockPrices("NASDAQ:MSFT", folder=cache, end=datetime.datetime(2014, 1, 15), url="google") except StockPricesHTTPException as e: warnings.warn(str(e)) return file = os.path.join(cache, "save.txt") if os.path.exists(file): os.remove(file) stock.to_csv(file) self.assertTrue(os.path.exists(file)) stock2 = StockPrices(file, sep="\t") self.assertEqual(stock.dataframe.shape, stock2.dataframe.shape) df = stock2.dataframe file = os.path.join(cache, "out_excel.xlsx") if os.path.exists(file): os.remove(file) df.to_excel(file) self.assertTrue(os.path.exists(file))
def test_save_stock_google(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") cache = os.path.abspath(os.path.split(__file__)[0]) cache = os.path.join(cache, "temp_cache_file_google") name = os.path.join(cache, TestLONGStockFile.tick.replace( ":", "_") + ".2000-01-03.2014-01-15.txt") if os.path.exists(name): os.remove(name) try: stock = StockPrices(TestLONGStockFile.tick, url=TestLONGStockFile.source, folder=cache, end=datetime.datetime(2014, 1, 15)) except ImportError as e: # There is an issue with pandas_datareader on travis. # Not up to date with the latest pandas. if is_travis_or_appveyor(): warnings.warn( "Probably an issue with pandas_datareader.\n" + str(e)) return else: raise e file = os.path.join(cache, "save.txt") if os.path.exists(file): os.remove(file) stock.to_csv(file) self.assertExists(file) stock2 = StockPrices(file, sep="\t") self.assertEqual(stock.dataframe.shape, stock2.dataframe.shape) df = stock2.dataframe file = os.path.join(cache, "out_excel.xlsx") if os.path.exists(file): os.remove(file) df.to_excel(file) self.assertExists(file)