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 test_parses_valid_infotable_xml(self): # TODO Make this accessible without hard-coded path with open('/home/chpack/Documents/python/quovo_challenge/christian_packard/fund_holdings/resources/gates_fund_complete_text_submission.txt', 'r') as text_submission: holdings_statement = text_submission.read() try: accepted_date, submission_type, holdings_xml = report13fhr.get_13f_xml(holdings_statement) self.assertTrue('informationTable' in holdings_xml) self.assertTrue('infoTable' in holdings_xml) xml.etree.ElementTree.fromstring(holdings_xml) except xml.etree.ElementTree.ParseError: self.fail('The text in holdings_statement raised ParseError unexpectedly')
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_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_empty_string_for_other_xml(self): text = '<DOCUMENT>\n<TYPE>13F-HR\n<SEQUENCE>1\n<FILENAME>primary_doc.xml\n<TEXT>\n<XML>\n<?xml version="1.0" encoding="UTF-8"?>\n<edgarSubmission xsi:schemaLocation="http://www.sec.gov/edgar/thirteenffiler eis_13F_Filer.xsd" xmlns="http://www.sec.gov/edgar/thirteenffiler" xmlns:ns1="http://www.sec.gov/edgar/common" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\n <headerData>\n <submissionType>13F-HR</submissionType>\n <filerInfo>\n <liveTestFlag>LIVE</liveTestFlag>\n <filer>\n <credentials>\n <cik>0001166559</cik>\n <ccc>XXXXXXXX</ccc>\n </credentials>\n </filer>\n <periodOfReport>09-30-2016</periodOfReport>\n </filerInfo>\n </headerData>\n <formData>\n <coverPage>\n <reportCalendarOrQuarter>09-30-2016</reportCalendarOrQuarter>\n <isAmendment>false</isAmendment>\n <filingManager>\n <name>Bill & Melinda Gates Foundation Trust</name>\n <address>\n <ns1:street1>2365 Carillon Point</ns1:street1>\n <ns1:city>Kirkland</ns1:city>\n <ns1:stateOrCountry>WA</ns1:stateOrCountry>\n <ns1:zipCode>98033</ns1:zipCode>\n </address>\n </filingManager>\n <reportType>13F HOLDINGS REPORT</reportType>\n <form13FFileNumber>028-10098</form13FFileNumber>\n <provideInfoForInstruction5>N</provideInfoForInstruction5>\n </coverPage>\n <signatureBlock>\n <name>Michael Larson</name>\n <title>Authorized Agent</title>\n <phone>425-889-7900</phone>\n <signature>/s/ Michael Larson</signature>\n <city>Kirkland</city>\n <stateOrCountry>WA</stateOrCountry>\n <signatureDate>11-14-2016</signatureDate>\n </signatureBlock>\n <summaryPage>\n <otherIncludedManagersCount>0</otherIncludedManagersCount>\n <tableEntryTotal>18</tableEntryTotal>\n <tableValueTotal>18452426</tableValueTotal>\n <isConfidentialOmitted>false</isConfidentialOmitted>\n </summaryPage>\n </formData>\n</edgarSubmission>\n</XML>\n</TEXT>\n</DOCUMENT>' accepted_date, submission_type, result = report13fhr.get_13f_xml(text) self.assertEqual('', result)