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 generate_13fhr_report(cik, forms, archives): # The parser looks for the most recent holdings holdings_statement = web.get_holding_info(archives[0]) accepted_date, submission_type, holdings_xml = report13fhr.get_13f_xml(holdings_statement[0]) current_13fhr = report13fhr.get_13f_holdings(cik, accepted_date, submission_type, holdings_xml) reportnames = current_13fhr.generate_report() return reportnames
def generate_13fhr_report(cik, archives, forms=['13F-HR', '13F-HR/A', 'N-Q']): """generate 13fhr report Requires 3 arguments cik, forms, and archives """ # The parser looks for the most recent holdings holdings_statement = web.get_holding_info(archives[0]) accepted_date, submission_type, holdings_xml = report13fhr.get_13f_xml( holdings_statement[0]) current_13fhr = report13fhr.get_13f_holdings(cik, accepted_date, submission_type, holdings_xml) reportnames = current_13fhr.generate_report() return reportnames
def test_parse_valid_xml_without_namespace(self): holding_xml = '/home/chpack/Documents/python/quovo_challenge/christian_packard/fund_holdings/resources/13f_hr_no_namespace.xml' cik = 'viiix' accepted_date = datetime.datetime.now() submission_type = '13F-HR' with open(holding_xml, 'r') as holdings: result = report13fhr.get_13f_holdings(cik, accepted_date, submission_type, holdings.read()) holding1 = result.holdings[0] holding2 = result.holdings[1] self.assertEqual(holding1.entity, 'ARCOS DORADOS HOLDINGS INC') self.assertEqual(holding1.shares, '3060500') self.assertEqual(holding1.value, '16129') self.assertEqual(holding2.entity, 'AUTONATION INC') self.assertEqual(holding2.shares, '1898717') self.assertEqual(holding2.value, '92487')
def test_parse_valid_xml_with_namespace(self): holding_xml = '/home/chpack/Documents/python/quovo_challenge/christian_packard/fund_holdings/resources/13f_hr_with_namespace.xml' cik = 'viiix' accepted_date = datetime.datetime.now() submission_type = '13F-HR' with open(holding_xml, 'r') as holdings: result = report13fhr.get_13f_holdings(cik, accepted_date, submission_type, holdings.read()) holding1 = result.holdings[0] holding2 = result.holdings[1] self.assertEqual(holding1.entity, 'ALLIANCE DATA SYSTEMS CORP') self.assertEqual(holding1.shares, '5000000') self.assertEqual(holding1.value, '1072650') self.assertEqual(holding2.entity, 'ALLISON TRANSMISSION HLDGS I') self.assertEqual(holding2.shares, '19125204') self.assertEqual(holding2.value, '548511')
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)