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)
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)
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)
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_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)
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