Exemplo n.º 1
0
def test_glb_index_in_sorted_list():
  """Test the glb_index_in_sorted_list function."""
  list = [1, 3, 5, 7, 9, 11]
  x = 5
  expected = 2
  assert_equal(glb_index_in_sorted_list(x, list), expected)
  x = 4
  expected = 1
  assert_equal(glb_index_in_sorted_list(x, list), expected)
Exemplo n.º 2
0
 def get_next_date(self, simulation_date):
   """Get the next date after the simulation for which new data is available.
   
   This will be None if there is no such future date.
   """
   i = glb_index_in_sorted_list(simulation_date + timedelta(1), self.storage['__filing_date']) + 1
   if i == len(self.storage['__filing_date']):
     return None
   return self.storage['__filing_date'][i] + timedelta(1)
Exemplo n.º 3
0
 def get_latest_filing(self, simulation_date):
   """Given the simulation_date, return the last filing period submitted to Edgar.
   
   This returns None if the given simulation_date occurs before the earliest filing
   with Edgar.
   """
   i = glb_index_in_sorted_list(simulation_date - timedelta(1), self.filing_dates)
   if i == -1:
     return None
   return self.period_end_dates[i]
Exemplo n.º 4
0
 def get_most_recent(self, type, simulation_date):
   """Get he most recent data of the given type filed before the simulation_date.
   
   Here type is a string used to identify which type of financial data
   to fetch, like 'cash flow'. Subclasses should implement this method
   with whatever financial data is relevant. For types not recognized,
   this method should return a ValueError.
   
   The simulation_date is a datetime.date object. The return value 
   should be (value, next_available_data). The value is the last known
   value the morning of the simulation date. The next_available_data 
   is the next possbile simulation_date for which new data will be 
   available. This will be None if there is no such sdate.
   """
   i = glb_index_in_sorted_list(simulation_date + timedelta(1), self.storage['__filing_date'])
   if i == -1:
     raise ValueError('No data available for type "%s".' % str(type))
   return self.storage[type][i]