Exemplo n.º 1
0
 def test_cache(self):
     pass # todo
     for test_data in self._data_cache:
         symbol, start_date, end_date = test_data
         stock = stock_value.StockHist(symbol, start_date, end_date)
         dates = stock.dates
         highs = stock.highs
         stock = None        # make sure we are going to use a new instance
         stock = stock_value.StockHist(symbol, start_date, end_date)
         self.assertEqual(dates, stock.dates)
         self.assertEqual(highs, stock.highs)
Exemplo n.º 2
0
 def test_no_dates(self):
     for test_data in self._data_no_end_date:
         symbol, start_date, expected_start = test_data
         expected_end = date.today() - timedelta(days=1)
         if start_date == None:
             stock = stock_value.StockHist(symbol)
         else:
             stock = stock_value.StockHist(symbol, start_date)
         self.assertEqual(symbol, stock.symbol)
         self.assertEqual(expected_start, stock.start_date)
         self.assertEqual(expected_end, stock.end_date)
Exemplo n.º 3
0
 def test_dates(self):
     for test_data in self._data_dates:
         symbol, start_date, end_date, expected_start, expected_end, expected_url = test_data
         stock = stock_value.StockHist(symbol, start_date, end_date)
         self.assertEqual(symbol, stock.symbol)
         self.assertEqual(expected_start, stock.start_date)
         self.assertEqual(expected_end, stock.end_date)
         self.assertEqual(expected_url, stock._make_url())
Exemplo n.º 4
0
 def setUpClass(cls):
     cls._my_path = os.path.abspath(os.path.dirname(__file__))
     cls._result_path = os.path.join(cls._my_path, 'result')
     cls._expected_path = os.path.join(cls._my_path, 'expected')
     os.mkdir(cls._result_path)
     stock_value.StockHist.default_path = cls._result_path
     cls._predictor = stock_value.LinearAdapter(
         linear_model.Ridge(alpha=0.1, fit_intercept=False))
     cls._comment = 'Ridge alpha=0.1'
     cls._histories = []
     for symbol, sdate, edate in cls._test_data:
         cls._histories.append(stock_value.StockHist(symbol, sdate, edate))
Exemplo n.º 5
0
 def test_content(self):
     for test_data in self._data_contents:
         symbol, start_date, end_date, expected_file = test_data
         expected_path = os.path.join(self._expected_path, expected_file)
         date_list = []
         high_list = []
         with open(expected_path, newline='') as f_expected:
             exp_reader = csv.reader(f_expected)
             next(exp_reader)     # skip the title row
             for row in exp_reader:
                 date_list.append(datetime.strptime(row[0], '%Y-%m-%d').date())
                 high_list.append(float(row[2]))
             date_list.reverse()  # Yahoo returns newest first; we need oldest first
             high_list.reverse()
         stock = stock_value.StockHist(symbol, start_date, end_date)
         self.assertEqual(date_list, stock.dates)
         self.assertEqual(high_list, stock.highs)