Exemplo n.º 1
0
    def test_covariance(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        cache = os.path.abspath(os.path.split(__file__)[0])
        cache = os.path.join(cache, "temp_cache_cov")
        stocks = [StockPrices("BNP.PA", folder=cache),
                  StockPrices("CA.PA", folder=cache),
                  StockPrices("SAF.PA", folder=cache),
                  ]

        dates = StockPrices.available_dates(stocks)
        ok = dates[dates["missing"] == 0]
        stocks = [v.keep_dates(ok) for v in stocks]

        cov = StockPrices.covariance(stocks)
        assert len(cov) == 3

        cor = StockPrices.covariance(stocks, cov=False)
        self.assertEqual(len(cor), 3)
        assert abs(cor.ix["BNP.PA", "BNP.PA"] - 1) < 1e-5
        assert abs(cor.ix[2, 2] - 1) < 1e-5

        ret, mat = StockPrices.covariance(stocks, cov=False, ret=True)
        self.assertEqual(len(ret), 3)
Exemplo n.º 2
0
    def test_graph(self) :
        """
        This test is failing with Python 3.4 if many pictures are drawn.
        """
        fLOG (__file__, self._testMethodName, OutputPrint = __name__ == "__main__")

        cache = os.path.abspath(os.path.split(__file__)[0])
        cache = os.path.join(cache, "temp_cache2")
        stocks = [ StockPrices ("BNP.PA", folder = cache),
                    StockPrices ("CA.PA", folder = cache),
                    StockPrices ("SAF.PA", folder = cache),
                    ]
                    
        if True:
            fig, ax, plt = StockPrices.draw(stocks, figsize=(16,8), field = ["Adj Close", "Close"])
            img = os.path.abspath(os.path.join(os.path.split(__file__)[0],"temp_image.png"))
            if os.path.exists(img): os.remove(img)
            fig.savefig(img)
            assert os.path.exists(img)

        if True and sys.version_info < (3,4) :
            fig, ax, plt = StockPrices.draw(stocks, begin="2010-01-01")
            img = os.path.abspath(os.path.join(os.path.split(__file__)[0],"temp_image2.png"))
            if os.path.exists(img): os .remove(img)
            fig.savefig(img)
            assert os.path.exists(img)
            
        if True and sys.version_info < (3,4):
            fig, ax, plt = StockPrices.draw(stocks[:1], begin="2010-01-01")
            img = os.path.abspath(os.path.join(os.path.split(__file__)[0],"temp_image3.png"))
            if os.path.exists(img): os .remove(img)
            fig.savefig(img)
            assert os.path.exists(img)     
Exemplo n.º 3
0
    def test_graph2(self):
        """
        This test is failing with Python 3.4 if many pictures are drawn.
        """
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        if is_travis_or_appveyor() == "appveyor":
            return

        fix_tkinter_issues_virtualenv()

        from matplotlib import pyplot as plt

        cache = os.path.abspath(os.path.split(__file__)[0])
        cache = os.path.join(cache, "temp_cache2")
        stock = StockPrices("BNP.PA", folder=cache)
        stock2 = StockPrices("CA.PA", folder=cache)

        fig, ax = plt.subplots(figsize=(16, 8))
        ax = stock.plot(ax=ax)
        ax = stock2.plot(ax=ax)
        img = os.path.abspath(
            os.path.join(
                os.path.split(__file__)[0],
                "temp_image2.png"))
        if os.path.exists(img):
            os.remove(img)
        fig.savefig(img)
        plt.close('all')
        assert os.path.exists(img)
Exemplo n.º 4
0
    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))
Exemplo n.º 5
0
    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_graph4(self):
        """
        This test is failing with Python 3.4 if many pictures are drawn.
        """
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")

        if is_travis_or_appveyor() == "appveyor":
            return

        fix_tkinter_issues_virtualenv()

        from matplotlib import pyplot as plt

        cache = os.path.abspath(os.path.split(__file__)[0])
        cache = os.path.join(cache, "temp_cache4")
        stock = StockPrices("BNP.PA", folder=cache)
        ret = stock.returns()["2012-04-01":"2014-04-15"]

        fig, ax = plt.subplots(figsize=(16, 8))
        ax = stock.plot(ax=ax)
        ax = ret.plot(ax=ax, axis=2)
        img = os.path.abspath(
            os.path.join(os.path.split(__file__)[0], "temp_image4.png"))
        if os.path.exists(img):
            os.remove(img)
        fig.savefig(img)
        plt.close('all')
        assert os.path.exists(img)
Exemplo n.º 7
0
    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))
Exemplo n.º 8
0
    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))
Exemplo n.º 9
0
    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))
Exemplo n.º 10
0
    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)
Exemplo n.º 11
0
    def test_covariance(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        cache = get_temp_folder(__file__, "temp_cache_cov")
        stocks = [
            StockPrices(t, folder=cache, url=TestStockHttp.source)
            for t in TestStockHttp.ticks
        ]

        dates = StockPrices.available_dates(stocks)
        ok = dates[dates["missing"] == 0]
        stocks = [v.keep_dates(ok) for v in stocks]

        cov = StockPrices.covariance(stocks)
        self.assertEqual(len(cov), 3)

        cor = StockPrices.covariance(stocks, cov=False)
        self.assertEqual(len(cor), 3)
        t = TestStockHttp.ticks[1]
        self.assertTrue(abs(cor.loc[t, t] - 1) < 1e-5)
        self.assertTrue(abs(cor.iloc[2, 2] - 1) < 1e-5)

        ret, mat = StockPrices.covariance(stocks, cov=False, ret=True)
        self.assertEqual(len(ret), 3)
Exemplo n.º 12
0
    def test_available_dates(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        cache = get_temp_folder(__file__, "temp_cache_dates")
        stocks = [
            StockPrices(t, folder=cache, url=TestStockHttp.source)
            for t in TestStockHttp.ticks
        ]
        av = StockPrices.available_dates(stocks)
        self.assertTrue(len(av) > 0)

        missing = stocks[-1].missing(av)
        self.assertTrue(missing is None or len(missing) > 0)
Exemplo n.º 13
0
    def test_available_dates(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        cache = os.path.abspath(os.path.split(__file__)[0])
        cache = os.path.join(cache, "temp_cache_dates")
        stocks = [
            StockPrices("BNP.PA", folder=cache),
            StockPrices("CA.PA", folder=cache),
            StockPrices("SAF.PA", folder=cache),
        ]
        av = StockPrices.available_dates(stocks)
        assert len(av) > 0

        missing = stocks[-1].missing(av)
        assert missing is None or len(missing) > 0
Exemplo n.º 14
0
    def test_graph3(self) :
        """
        This test is failing with Python 3.4 if many pictures are drawn.
        """
        fLOG (__file__, self._testMethodName, OutputPrint = __name__ == "__main__")

        cache = os.path.abspath(os.path.split(__file__)[0])
        cache = os.path.join(cache, "temp_cache3")
        stock = StockPrices ("BNP.PA", folder = cache)
        stock2 = StockPrices ("CA.PA", folder = cache)
                    
        fig, ax, plt = stock.plot(figsize=(16,8))
        fig, ax, plt = stock2.plot(existing=(fig,ax), axis=2)
        img = os.path.abspath(os.path.join(os.path.split(__file__)[0],"temp_image3.png"))
        if os.path.exists(img): os.remove(img)
        fig.savefig(img)
        assert os.path.exists(img)
Exemplo n.º 15
0
    def test_covariance(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        cache = os.path.abspath(os.path.split(__file__)[0])
        cache = os.path.join(cache, "temp_cache_cov")
        stocks = [
            StockPrices("BNP.PA", folder=cache),
            StockPrices("CA.PA", folder=cache),
            StockPrices("SAF.PA", folder=cache),
        ]

        dates = StockPrices.available_dates(stocks)
        ok = dates[dates["missing"] == 0]
        stocks = [v.keep_dates(ok) for v in stocks]

        cov = StockPrices.covariance(stocks)
        assert len(cov) == 3

        cor = StockPrices.covariance(stocks, cov=False)
        self.assertEqual(len(cor), 3)
        assert abs(cor.ix["BNP.PA", "BNP.PA"] - 1) < 1e-5
        assert abs(cor.ix[2, 2] - 1) < 1e-5

        ret, mat = StockPrices.covariance(stocks, cov=False, ret=True)
        self.assertEqual(len(ret), 3)
Exemplo n.º 16
0
 def test_index(self):
     fLOG(__file__,
          self._testMethodName,
          OutputPrint=__name__ == "__main__")
     cache = get_temp_folder(__file__, "temp_cache_index")
     stock = StockPrices(TestStockHttp.ticks[0],
                         folder=cache,
                         end=datetime.datetime(2014, 1, 15),
                         url=TestStockHttp.source)
     some = stock["2001-01-01":"2002-02-02"]
     self.assertTrue(isinstance(some, StockPrices))
     self.assertTrue(len(some) < 1000)
Exemplo n.º 17
0
 def test_index(self):
     fLOG(__file__,
          self._testMethodName,
          OutputPrint=__name__ == "__main__")
     cache = os.path.abspath(os.path.split(__file__)[0])
     cache = os.path.join(cache, "temp_cache_index")
     stock = StockPrices("BNP.PA",
                         folder=cache,
                         end=datetime.datetime(2014, 1, 15))
     some = stock["2001-01-01":"2002-02-02"]
     assert isinstance(some, StockPrices)
     assert len(some) < 1000
    def test_graph3(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")

        fix_tkinter_issues_virtualenv()

        from matplotlib import pyplot as plt

        cache = os.path.abspath(os.path.split(__file__)[0])
        cache = os.path.join(cache, "temp_cache3")
        stock = StockPrices(TestStockGraph3.tick[0],
                            folder=cache,
                            url=TestStockGraph3.source)
        stock2 = StockPrices(TestStockGraph3.tick[1],
                             folder=cache,
                             url=TestStockGraph3.source)

        fig, ax = plt.subplots(figsize=(16, 8))
        ax = stock.plot(ax=ax)
        ax = stock2.plot(ax=ax, axis=2)
        img = os.path.abspath(
            os.path.join(os.path.split(__file__)[0], "temp_image3.png"))
        if os.path.exists(img):
            os.remove(img)
        fig.savefig(img)
        plt.close('all')
        self.assertExists(img)
Exemplo n.º 19
0
 def test_available_dates(self) :
     fLOG (__file__, self._testMethodName, OutputPrint = __name__ == "__main__")
     cache = os.path.abspath(os.path.split(__file__)[0])
     cache = os.path.join(cache, "temp_cache2")
     stocks = [ StockPrices ("BNP.PA", folder = cache),
                 StockPrices ("CA.PA", folder = cache),
                 StockPrices ("SAF.PA", folder = cache),
                 ]
     av = StockPrices.available_dates(stocks)
     assert len(av)>0
     
     missing = stocks[-1].missing(av)
     assert missing is None or len(missing)>0
    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)
Exemplo n.º 21
0
 def test_download_stock(self):
     fLOG(__file__,
          self._testMethodName,
          OutputPrint=__name__ == "__main__")
     cache = get_temp_folder(__file__, "temp_cache_download_http")
     stock = StockPrices(TestStockHttp.ticks[0],
                         folder=cache,
                         end=datetime.datetime(2014, 1, 15),
                         url=TestStockHttp.source)
     u = TestStockHttp.ticks[0].replace(":", "_")
     name = os.path.join(cache, u + ".2000-01-03.2014-01-15.txt")
     self.assertTrue(os.path.exists(name))
     df = stock.dataframe
     self.assertTrue(len(df) > 0)
Exemplo n.º 22
0
 def test_download_stock(self):
     fLOG(__file__,
          self._testMethodName,
          OutputPrint=__name__ == "__main__")
     cache = os.path.abspath(os.path.split(__file__)[0])
     cache = os.path.join(cache, "temp_cache_download_http")
     name = os.path.join(cache, "BNP.PA.2000-01-03.2014-01-15.txt")
     if os.path.exists(name):
         os.remove(name)
     stock = StockPrices("BNP.PA",
                         folder=cache,
                         end=datetime.datetime(2014, 1, 15))
     assert os.path.exists(name)
     df = stock.dataframe
     assert len(df) > 0
Exemplo n.º 23
0
 def test_no_wifi(self):
     fLOG(__file__,
          self._testMethodName,
          OutputPrint=__name__ == "__main__")
     data = os.path.abspath(os.path.split(__file__)[0])
     data = os.path.join(data, "data")
     file = os.path.join(data, "BNP.PA.2000-01-03.2014-02-24.txt")
     fLOG(os.path.exists(file))
     fLOG(file)
     try:
         StockPrices(file)
     except StockPricesException as e:
         if "pandas cannot parse the file" not in str(e):
             raise Exception("unexpected error (2)") from e
         if "Error tokenizing data" in str(e):
             raise Exception("unexpected error (3)") from e
 def test_download_stock_google(self):
     fLOG(
         __file__,
         self._testMethodName,
         OutputPrint=__name__ == "__main__")
     cache = get_temp_folder(__file__, "temp_url_google")
     try:
         stock = StockPrices("NASDAQ:MSFT", folder=cache,
                             begin=datetime.datetime(2014, 1, 15))
     except StockPricesHTTPException as e:
         warnings.warn(str(e))
         return
     df = stock.dataframe
     dmin = df.Date.min()
     self.assertIn("2014", str(dmin))
     self.assertTrue(stock.url_.startswith(
         "https://finance.google.com/finance/historical?q=NASDAQ:MSFT&startdate=Jan+15%2C+2014"))
 def test_download_stock_yahoo(self):
     fLOG(__file__,
          self._testMethodName,
          OutputPrint=__name__ == "__main__")
     cache = get_temp_folder(__file__, "temp_url_yahoo")
     exc = []
     for n in range(0, 4):
         stock = StockPrices("^FCHI",
                             folder=cache,
                             url=TestStockUrlYahoo.source,
                             begin=datetime.datetime(2014, 1, 15))
         df = stock.dataframe
         dmin, dmax = df.Date.min(), df.Date.max()
         try:
             self.assertIn("2014", str(dmin))
             self.assertNotEqual(dmin, dmax)
             if "^FCHI.2014-01-15" not in stock.url_:
                 raise AssertionError(stock.url_)
             return
         except AssertionError as e:
             exc.append(e)
     if len(exc) > 0:
         e = exc[0]
         raise AssertionError('nb tries={0}'.format(len(exc))) from e
Exemplo n.º 26
0
    def test_graph(self):
        """
        This test is failing with Python 3.4 if many pictures are drawn.
        """
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        fix_tkinter_issues_virtualenv()

        from matplotlib import pyplot as plt

        cache = os.path.abspath(os.path.split(__file__)[0])
        cache = os.path.join(cache, "temp_cache2")
        stocks = [StockPrices("BNP.PA", folder=cache),
                  StockPrices("CA.PA", folder=cache),
                  StockPrices("SAF.PA", folder=cache),
                  ]

        if True:
            fLOG("A", sys.executable)
            fig, ax = plt.subplots()
            ax = StockPrices.draw(
                stocks, figsize=(
                    16, 8), field=[
                    "Adj Close", "Close"],
                ax=ax)
            img = os.path.abspath(
                os.path.join(
                    os.path.split(__file__)[0],
                    "temp_image.png"))
            if os.path.exists(img):
                os.remove(img)
            fig.savefig(img)
            plt.close('all')
            assert os.path.exists(img)

        if True:
            fLOG("B")
            fig, ax = plt.subplots()
            ax = StockPrices.draw(stocks, begin="2010-01-01", ax=ax)
            img = os.path.abspath(
                os.path.join(
                    os.path.split(__file__)[0],
                    "temp_image2.png"))
            if os.path.exists(img):
                os .remove(img)
            fig.savefig(img)
            plt.close('all')
            assert os.path.exists(img)

        if True:
            fLOG("C")
            fig, ax = plt.subplots()
            ax = StockPrices.draw(stocks[:1], begin="2010-01-01", ax=ax)
            img = os.path.abspath(
                os.path.join(
                    os.path.split(__file__)[0],
                    "temp_image3.png"))
            if os.path.exists(img):
                os .remove(img)
            fig.savefig(img)
            plt.close('all')
            assert os.path.exists(img)

        fLOG("thisend")
Exemplo n.º 27
0
    def test_graph(self):
        """
        This test is failing with Python 3.4 if many pictures are drawn.
        """
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        fix_tkinter_issues_virtualenv()

        from matplotlib import pyplot as plt

        cache = os.path.abspath(os.path.split(__file__)[0])
        cache = os.path.join(cache, "temp_cache2")
        stocks = [StockPrices(t, folder=cache, url=TestStockGraph.source)
                  for t in TestStockGraph.tick]

        if True:
            fLOG("A", sys.executable)
            fig, ax = plt.subplots()
            ax = StockPrices.draw(
                stocks, figsize=(
                    16, 8), field=[
                    "Open", "Close"],
                ax=ax)
            img = os.path.abspath(
                os.path.join(
                    os.path.split(__file__)[0],
                    "temp_image.png"))
            if os.path.exists(img):
                os.remove(img)
            fig.savefig(img)
            plt.close('all')
            self.assertExists(img)

        if True:
            fLOG("B")
            fig, ax = plt.subplots()
            ax = StockPrices.draw(stocks, begin="2010-01-01", ax=ax)
            img = os.path.abspath(
                os.path.join(
                    os.path.split(__file__)[0],
                    "temp_image2.png"))
            if os.path.exists(img):
                os .remove(img)
            fig.savefig(img)
            plt.close('all')
            self.assertExists(img)

        if True:
            fLOG("C")
            fig, ax = plt.subplots()
            ax = StockPrices.draw(stocks[:1], begin="2010-01-01", ax=ax)
            img = os.path.abspath(
                os.path.join(
                    os.path.split(__file__)[0],
                    "temp_image3.png"))
            if os.path.exists(img):
                os .remove(img)
            fig.savefig(img)
            plt.close('all')
            self.assertExists(img)

        fLOG("thisend")