def test_google_boundry(self):
     quarterly_eps = EPS.quarterly()
     getter = AccountingMetricGetter(metric=quarterly_eps,
                                     filing_getter=HTMLEdgarDriver)
     date = datetime.date(2013, 4, 25)  #Google filed on this date.
     interval_start, _, _ = getter.get_data(symbol='goog', date=date)
     self.assertEqual(interval_start, datetime.date(2012, 10, 31))
 def test_google(self):
     quarterly_eps = EPS.quarterly()
     getter = AccountingMetricGetter(metric=quarterly_eps, filing_getter=HTMLEdgarDriver)
     date = datetime.date(2013, 1, 2)
     interval_start, earnings, interval_end = getter.get_data(symbol="goog", date=date)
     self.assertEqual(interval_start, datetime.date(2012, 10, 31))
     self.assertEqual(interval_end, datetime.date(2013, 4, 25))
     self.assertEqual(earnings, 6.53)
 def test_no_filings_available(self):
     mock_filing_getter = mock.Mock()
     mock_filing_getter.get_filing.side_effect = NoFilingsNotAvailable()
     getter = AccountingMetricGetter(metric=mock.Mock(), filing_getter=mock_filing_getter)
     with self.assertRaises(NoDataForStockForRange) as cm:
         getter.get_data(symbol=None, date=datetime.date(2012, 12, 1))
     self.assertIsNone(cm.exception.start)
     self.assertIsNone(cm.exception.end)
Exemplo n.º 4
0
 def test_google(self):
     getter = AccountingMetricGetter(metric=QuarterlyEPS,
                                     filing_getter=HTMLEdgarDriver)
     date = datetime.date(2013, 1, 2)
     interval_start, earnings, interval_end = getter.get_data(symbol='goog',
                                                              date=date)
     self.assertEqual(interval_start, datetime.date(2012, 10, 30))
     self.assertEqual(interval_end, datetime.date(2013, 4, 25))
     self.assertEqual(earnings, 6.53)
 def test_google(self):
     getter = AccountingMetricGetter(metric=QuarterlyEPS, 
                                     filing_getter=HTMLEdgarDriver)
     date = datetime.date(2013, 1, 2)
     interval_start, earnings, interval_end = getter.get_data(symbol='goog', 
                                                              date=date)
     self.assertEqual(interval_start, datetime.date(2012, 10, 30))
     self.assertEqual(interval_end, datetime.date(2013, 4, 25))
     self.assertEqual(earnings, 6.53)
 def test_filing_not_available_until(self):
     mock_filing_getter = mock.Mock()
     end_date = datetime.date(2012, 12, 1)
     mock_filing_getter.get_filing.side_effect = FilingNotAvailableForDate(message='', 
                                                                           end=end_date)
     getter = AccountingMetricGetter(metric=mock.Mock(), filing_getter=mock_filing_getter)
     with self.assertRaises(NoDataForStockForRange) as cm:
         getter.get_data(symbol=None, date=datetime.date(2012, 12, 1))
     self.assertEqual(cm.exception.end, end_date)
 def test_metric_not_in_filing(self):
     mock_filing_getter = mock.Mock()
     mock_filing = mock.Mock()
     mock_filing.date = datetime.date(2012, 11, 30)
     mock_filing.next_filing = None
     mock_filing_getter.get_filing.return_value = mock_filing
     mock_metric = mock.Mock()
     mock_metric.value_from_filing.side_effect = ValueNotInFilingDocument()
     getter = AccountingMetricGetter(metric=mock_metric,
                                     filing_getter=mock_filing_getter)
     with self.assertRaises(NoDataForStockForRange):
         getter.get_data(symbol='ABC', date=datetime.datetime(2012, 12, 1))
Exemplo n.º 8
0
def mongo_fundamentals_cache(metric, mongo_host='localhost', mongo_port=27017,
                             filing_getter=HTMLEdgarDriver):
    mongo_client = pymongo.MongoClient(mongo_host, mongo_port)
    mongo_collection = mongo_client.fundamentals.fundamentals
    db = MongoIntervalseries(mongo_collection=mongo_collection, 
                         metric=metric.name)
    metric_getter = AccountingMetricGetter(metric=metric,
                                           filing_getter=filing_getter)
    cache = FinancialIntervalCache(get_data=metric_getter.get_data, database=db)
    return cache
Exemplo n.º 9
0
def sqlite_fundamentals_cache(metric, 
                              db_file_path=DEFAULT_FUNDAMENTALS_PATH, 
                              filing_getter=HTMLEdgarDriver):
    connection = sqlite_drivers.SQLiteIntervalseries.connect(db_file_path)
    driver = sqlite_drivers.SQLiteIntervalseries(connection=connection,
                                                 table='fundamentals',
                                                 metric=metric.name)
    metric_getter = AccountingMetricGetter(metric=metric, 
                                           filing_getter=filing_getter)
    
    cache = FinancialIntervalCache(get_data=metric_getter.get_data, 
                                     database=driver)
    return cache
Exemplo n.º 10
0
 def test_border_behavior(self):
     '''Fundamentals were being inserted twice because of an off by one error.'''
     metric = accounting_metrics.QuarterlyEPS
     symbol = 'CSCO'
     connection = sqlite3.connect(':memory:', detect_types=sqlite3.PARSE_DECLTYPES)
     driver = SQLiteIntervalseries(connection=connection,
                                  table='fundamentals',
                                  metric=metric.name)
     metric_getter = AccountingMetricGetter(metric=metric, 
                                        filing_getter=HTMLEdgarDriver)
     cache = FinancialIntervalCache(get_data=metric_getter.get_data, database=driver)
     dates = {datetime.datetime(2010, 2, 17)}
     list(cache.get(symbol, dates=dates))
     
     count_query = "SELECT COUNT(*)  AS count FROM fundamentals WHERE symbol = '{}'".format(symbol)
     count = connection.execute(count_query).next()['count']
     self.assertEqual(count, 1)
     list(cache.get(symbol, dates=dates))
     count = connection.execute(count_query).next()['count']
     self.assertEqual(count, 1)
Exemplo n.º 11
0
 def test_google_boundry(self):
     getter = AccountingMetricGetter(metric=QuarterlyEPS,
                                     filing_getter=HTMLEdgarDriver)
     date = datetime.date(2013, 4, 25)  #Google filed on this date.
     interval_start, _, _ = getter.get_data(symbol='goog', date=date)
     self.assertEqual(interval_start, datetime.date(2012, 10, 30))