def test_valid_nq_filing_with_text_report(self): ## Jim wants to find out the latest holdings of a fund he's ## invested in, the Vanguard Institutional Index Funds ## He searches by the trust's ticker cik = 'viiix' # The parser performs the initial search on EDGAR database forms = ['N-Q'] submission_type, archives = web.get_archive_links(cik, *forms) # The parser looks for the most recent holdings holdings_statement = web.get_holding_info(archives[0]) # With the complete submission, the parser extracts the accepted_date, # series / contract information, and parses the HTML to read the holdings # into a more useable form current_nq = reportnq.get_nq_report(holdings_statement[0]) self.assertEqual(current_nq.cik, '0000862084') self.assertEqual(current_nq.submission_type, 'N-Q') # With the holdings extracted, the parser prints them into neatly # formatted tab-separated reports for Mim reportnames = current_nq.generate_report() ## Jim inspects the reports to make sure he has the correct info for reportname in reportnames: with open('reports/' + reportname, 'r') as report: reader = csv.DictReader(report, delimiter='\t') for row in reader: self.assertIsInstance(int(row['value'].replace(',', '')), int) self.assertIsInstance(int(row['shares'].replace(',', '')), int)
def test_valid_13fhr_filing(self): ## Mary wants to find out the latest holdings of a fund she's ## invested in, the Bill and Melinda Gates Foundation Trust ## She searches by the trust's CIK number cik = '0001166559' # The parser performs the initial search on EDGAR database forms = ['13F-HR', '13F-HR/A'] submission_type, archives = web.get_archive_links(cik, *forms) # The parser looks for the most recent holdings holdings_statement = web.get_holding_info(archives[0]) # With the complete submission, the parser cuts down unnecessary info accepted_date, submission_type, holdings_xml = report13fhr.get_13f_xml(holdings_statement[0]) # With all the holdings statements, the parser converts the xml # into a more useable form current_13fhr = report13fhr.get_13f_holdings(cik, accepted_date, submission_type, holdings_xml) self.assertEqual(current_13fhr.cik, '0001166559') self.assertEqual(current_13fhr.submission_type, '13F-HR') # With the holdings extracted, the parser prints them into a neatly # formatted tab-separated report for Mary reportnames = current_13fhr.generate_report() ## Mary inspects the report to make sure she has the correct info with open('reports/' + reportnames[0], 'r') as report: reader = csv.DictReader(report, delimiter='\t') for row in reader: self.assertIsInstance(int(row['value'].replace(',', '')), int) self.assertIsInstance(int(row['shares'].replace(',', '')), int)
def test_valid_nq_filing_with_text_report(self): ## Jim wants to find out the latest holdings of a fund he's ## invested in, the Vanguard Institutional Index Funds ## He searches by the trust's ticker cik = 'viiix' # The parser performs the initial search on EDGAR database forms = ['N-Q'] submission_type, archives = web.get_archive_links(cik, *forms) # The parser looks for the most recent holdings holdings_statement = web.get_holding_info(archives[0]) # With the complete submission, the parser extracts the accepted_date, # series / contract information, and parses the HTML to read the holdings # into a more useable form current_nq = reportnq.get_nq_report(holdings_statement[0]) self.assertEqual(current_nq.cik, '0000862084') self.assertEqual(current_nq.submission_type, 'N-Q') # With the holdings extracted, the parser prints them into neatly # formatted tab-separated reports for Mim series_plural = current_nq.generate_report() ## Jim inspects the reports to make sure he has the correct info for series in series_plural: for holding in series['holdings']: self.assertIsInstance(int(holding[1].replace(',', '')), int) self.assertIsInstance(int(holding[2].replace(',', '')), int)
def generate_report(cik, forms): submission_type, archives = web.get_archive_links(cik, *forms) if submission_type == '13F-HR' or submission_type == '13F-HR/A': logger.info('Found 13F-HR filing, proceeding to generate report...') return generate_13fhr_report(cik, forms, archives) elif submission_type == 'N-Q': logger.info('Found N-Q filing, proceeding to generate report...') return generate_nq_report(cik, forms, archives) else: logger.error('Don\'t know how to parse form' + submission_type) print('Don\'t know how to parse form' + submission_type) sys.exit(1)
def generate_report(cik, forms=['13F-HR', '13F-HR/A', 'N-Q']): """generate report Requires 1 arguments cik Decides to generate 13fhr or nq report based on available filing """ submission_type, archives = web.get_archive_links(cik, *forms) if submission_type == '13F-HR' or submission_type == '13F-HR/A': logger.info('Found 13F-HR filing, proceeding to generate report...') return generate_13fhr_report(cik, archives) elif submission_type == 'N-Q': logger.info('Found N-Q filing, proceeding to generate report...') return generate_nq_report(cik, archives) else: raise nq.InvalidContractTextException( 'Too few elements in contract text')
def test_valid_13fhr_filing(self): ## Mary wants to find out the latest holdings of a fund she's ## invested in, the Bill and Melinda Gates Foundation Trust ## She searches by the trust's CIK number cik = '0001166559' # The parser performs the initial search on EDGAR database forms = ['13F-HR', '13F-HR/A'] submission_type, archives = web.get_archive_links(cik, *forms) # The parser looks for the most recent holdings holdings_statement = web.get_holding_info(archives[0]) # With the complete submission, the parser cuts down unnecessary info accepted_date, submission_type, holdings_xml = report13fhr.get_13f_xml( holdings_statement[0]) # With all the holdings statements, the parser converts the xml # into a more useable form current_13fhr = report13fhr.get_13f_holdings(cik, accepted_date, submission_type, holdings_xml) self.assertEqual(current_13fhr.cik, '0001166559') self.assertEqual(current_13fhr.submission_type, '13F-HR') # With the holdings extracted, the parser prints them into a neatly # formatted tab-separated report for Mary report = io.StringIO(current_13fhr.generate_report()) ## Mary inspects the report to make sure she has the correct info reader = csv.DictReader(report, delimiter='\t') for row in reader: self.assertIsInstance(int(row['value'].replace(',', '')), int) self.assertIsInstance(int(row['shares'].replace(',', '')), int)
def test_returns_links_for_nq(self): ticker = 'viiix' forms = ['N-Q'] self.assertNotEqual([], web.get_archive_links(ticker, *forms))
def test_returns_links_for_13fhr(self): ticker = '0001166559' forms = ['13F-HR', '13F-HR/A'] self.assertNotEqual([], web.get_archive_links(ticker, *forms))
def test_doesnt_return_links_for_bad_forms(self): ticker = 'viiix' forms = ['Q-N'] self.assertEqual(('', []), web.get_archive_links(ticker, *forms))