class Test(unittest.TestCase): def setUp(self): turn_on_request_caching() test_filing_path = os.path.join(TEST_DOCS_DIR, 'aapl-20121229.xml') with open(test_filing_path) as f: test_statement_xml_dict = xmltodict.parse(f.read()) self.xbrl_dict = test_statement_xml_dict['xbrl'] self.xbrl_doc = XBRLDocument(None) self.xbrl_doc._xbrl_dict_ = self.xbrl_dict def test_context_dates(self): context_id = 'eol_PE2035----1210-Q0013_STD_98_20111231_0' context = self.xbrl_doc.time_span_contexts_dict()[context_id] self.assertEqual(context.start_date, datetime.date(2011, 9, 25)) self.assertEqual(context.end_date, datetime.date(2011, 12, 31)) def test_document_downloading(self): doc = XBRLDocument( 'http://www.sec.gov/Archives/edgar/data/320193/000119312513022339/aapl-20121229.xml' ) self.assertDictEqual(doc._xbrl_dict, self.xbrl_dict) def test_get_most_recent_metric_value(self): metric = mock.Mock() metric.xbrl_tags = ['us-gaap:EarningsPerShareDiluted'] self.assertEqual(self.xbrl_doc.latest_metric_value(metric), 13.81)
class Test(unittest.TestCase): def setUp(self): turn_on_request_caching() test_filing_path = os.path.join(TEST_DOCS_DIR, 'aapl-20121229.xml') with open(test_filing_path) as f: test_statement_xml_dict = xmltodict.parse(f.read()) self.xbrl_dict = test_statement_xml_dict['xbrl'] self.xbrl_doc = XBRLDocument(None) self.xbrl_doc._xbrl_dict_ = self.xbrl_dict def test_context_dates(self): context_id = 'eol_PE2035----1210-Q0013_STD_98_20111231_0' context = self.xbrl_doc.time_span_contexts_dict()[context_id] self.assertEqual(context.start_date, datetime.date(2011, 9, 25)) self.assertEqual(context.end_date, datetime.date(2011, 12, 31)) def test_document_downloading(self): doc = XBRLDocument('http://www.sec.gov/Archives/edgar/data/320193/000119312513022339/aapl-20121229.xml') self.assertDictEqual(doc._xbrl_dict, self.xbrl_dict) def test_get_most_recent_metric_value(self): metric = mock.Mock() metric.xbrl_tags = ['us-gaap:EarningsPerShareDiluted'] self.assertEqual(self.xbrl_doc.latest_metric_value(metric), 13.81)
def setUp(self): turn_on_request_caching() test_filing_path = os.path.join(TEST_DOCS_DIR, 'aapl-20121229.xml') with open(test_filing_path) as f: test_statement_xml_dict = xmltodict.parse(f.read()) self.xbrl_dict = test_statement_xml_dict['xbrl'] self.xbrl_doc = XBRLDocument(None) self.xbrl_doc._xbrl_dict_ = self.xbrl_dict
def ex(): print 'Calculating key accounting figures for Apple (2012 filing)' ticker = 'aapl' # filings = edgar.get_filings(symbol=ticker, filing_type='10-Q') # filing = filings[filings.bisect(date(2013, 1, 23)) - 1] # print filing url = 'http://www.sec.gov/Archives/edgar/data/320193/000119312513022339/aapl-20121229.xml' doc = XBRLDocument.gets_XBRL_from_edgar(xbrl_url=url) # filing = Filing(filing_date=None, document=xbrl_document, next_filing=None) tags = [ # short-name, tagname, 'd/i' = duration or instance ['assets', 'us-gaap:Assets', 'i'], ['liabilites', 'us-gaap:Liabilities', 'i'], ['shares', 'dei:EntityCommonStockSharesOutstanding', 'i'], ['equity', 'us-gaap:StockholdersEquity', 'i'], ['eps', 'us-gaap:EarningsPerShareDiluted', 'd'] ] out = {} for tag in tags: context = DurationContext if tag[2] == 'd' else InstantContext metric_params = XBRLMetricParams(possible_tags=[tag[1]], context_type=context) out[tag[0]] = doc.latest_metric_value(metric_params=metric_params) out['book'] = out['assets'] - out['liabilites'] out['book-ps'] = out['book'] / out['shares'] for k in out: print k, ': ', out[k]
def test_GOOG_shareholders_equity(self): sec_value = 994.77 doc_path = os.path.join(TEST_DOCS_DIR, 'goog-20120630.xml') xbrl_document = XBRLDocument.gets_XBRL_locally(file_path=doc_path) filing = Filing(filing_date=None, document=xbrl_document, next_filing=None) book_value_per_share = BookValuePerShare.value_from_filing(filing) self.assertAlmostEqual(book_value_per_share, sec_value, places=1)
def test_GOOG_shareholders_equity(self): sec_value = 994.77 doc_path = tests.asset_file_path('goog-20120630.xml') xbrl_document = XBRLDocument.gets_XBRL_locally(file_path=doc_path) filing = Filing(filing_date=None, document=xbrl_document, next_filing=None) book_value_per_share = BookValuePerShare.value_from_filing(filing) self.assertAlmostEqual(book_value_per_share, sec_value, places=1)
def ex(): print 'Calculating key accounting figures for Apple (2012 filing)' ticker = 'aapl' # filings = edgar.get_filings(symbol=ticker, filing_type='10-Q') # filing = filings[filings.bisect(date(2013, 1, 23)) - 1] # print filing url = 'http://www.sec.gov/Archives/edgar/data/320193/000119312513022339/aapl-20121229.xml' doc = XBRLDocument.gets_XBRL_from_edgar(xbrl_url=url) # filing = Filing(filing_date=None, document=xbrl_document, next_filing=None) tags = [ # short-name, tagname, 'd/i' = duration or instance ['assets', 'us-gaap:Assets', 'i'], ['liabilites', 'us-gaap:Liabilities', 'i'], ['shares', 'dei:EntityCommonStockSharesOutstanding', 'i'], ['equity', 'us-gaap:StockholdersEquity', 'i'], ['eps', 'us-gaap:EarningsPerShareDiluted', 'd'] ] out = {} for tag in tags: context = DurationContext if tag[2] == 'd' else InstantContext metric_params = XBRLMetricParams(possible_tags=[tag[1]], context_type=context ) out[tag[0]] = doc.latest_metric_value(metric_params=metric_params) out['book'] = out['assets'] - out['liabilites'] out['book-ps'] = out['book'] / out['shares'] for k in out: print k, ': ', out[k]
def test_document_downloading(self): url = 'http://www.sec.gov/Archives/edgar/data/320193/000119312513022339/aapl-20121229.xml' test_filing_path = tests.asset_file_path('aapl-20121229.xml') with open(test_filing_path) as f: test_statement_xml_dict = xmltodict.parse(f.read()) xbrl_dict = test_statement_xml_dict['xbrl'] doc = XBRLDocument.gets_XBRL_from_edgar(xbrl_url=url) self.assertDictEqual(doc._xbrl_dict, xbrl_dict)
def test_appl(self): """value computed from http://www.sec.gov/cgi-bin/viewer?action=view&cik=320193&accession_number=0001193125-13-022339&xbrl_type=v#. """ sec_value = 135.6 doc_path = os.path.join(TEST_DOCS_DIR, "aapl-20121229.xml") xbrl_document = XBRLDocument.gets_XBRL_locally(file_path=doc_path) filing = Filing(filing_date=None, document=xbrl_document, next_filing=None) book_value_per_share = BookValuePerShare.value_from_filing(filing) self.assertAlmostEqual(book_value_per_share, sec_value, places=1)
def test_appl(self): '''value computed from http://www.sec.gov/cgi-bin/viewer?action=view&cik=320193&accession_number=0001193125-13-022339&xbrl_type=v#. ''' sec_value = 135.6 doc_path = tests.asset_file_path('aapl-20121229.xml') xbrl_document = XBRLDocument.gets_XBRL_locally(file_path=doc_path) filing = Filing(filing_date=None, document=xbrl_document, next_filing=None) book_value_per_share = BookValuePerShare.value_from_filing(filing) self.assertAlmostEqual(book_value_per_share, sec_value, places=1)
def from_xbrl_url(cls, filing_date, xbrl_url): '''constructor.''' document = XBRLDocument(xbrl_url=xbrl_url) return cls(filing_date=filing_date, document=document)
def setUp(self): test_filing_path = os.path.join(TEST_DOCS_DIR, 'aapl-20121229.xml') self.xbrl_doc = XBRLDocument.gets_XBRL_locally(file_path=test_filing_path)
def setUp(self): test_filing_path = tests.asset_file_path('aapl-20121229.xml') self.xbrl_doc = XBRLDocument.gets_XBRL_locally(file_path=test_filing_path)
def from_xbrl_url(cls, filing_date, xbrl_url): """constructor.""" document = XBRLDocument.gets_XBRL_from_edgar(xbrl_url=xbrl_url) return cls(filing_date=filing_date, document=document)
def test_document_downloading(self): doc = XBRLDocument( 'http://www.sec.gov/Archives/edgar/data/320193/000119312513022339/aapl-20121229.xml' ) self.assertDictEqual(doc._xbrl_dict, self.xbrl_dict)