def test_index_in_sorted_list():
  """Test the index_in_sorted_list function."""
  list = [1, 3, 5, 7, 9, 11]
  x = 5
  expected = 2
  assert_equal(index_in_sorted_list(x, list), expected)
  x = 4
  expected = -1
  assert_equal(index_in_sorted_list(x, list), expected)
Beispiel #2
0
 def get_end_of_day(self, symbol):
   """Gets the EndOfDay object associated with the given stock.
   
   symbol -- The ticker symbol of the stock to get.
   
   The start_date and end_date of the returned object will match the start_date and
   end_date of the simulation.
   """
   if not self.__end_of_day_items.has_key(symbol):
     self.__end_of_day_items[symbol] = self.end_of_day_class(symbol, self.start_date, self.end_date)
   if not self.__date_offsets.has_key(symbol):
     dates = self.__end_of_day_items[Config().BACKTEST_SYMBOL_FOR_ALL_DATES].dates
     self.__date_offsets[symbol] = index_in_sorted_list(self.__end_of_day_items[symbol].dates[0], dates)
   return self.__end_of_day_items[symbol]