Skip to content

Instantly share code, notes, and snippets.

@mjbommar
Created October 26, 2010 13:45
Show Gist options
  • Save mjbommar/646917 to your computer and use it in GitHub Desktop.
Save mjbommar/646917 to your computer and use it in GitHub Desktop.
Process the Permanent Open Market Operation (POMO) XML data from the NY Federal Reserve Bank.
import csv
import dateutil.parser
import lxml, lxml.etree
rangeString = '20050825_20101025'
xmlRoot = lxml.etree.parse("data/pomo_{0}.xml".format(rangeString)).getroot()
xmlData = xmlRoot.getchildren()[1]
pomoData = []
for xmlGroup in xmlData:
operationDate = dateutil.parser.parse(xmlGroup.attrib['operationDate'])
operationDirection = xmlGroup.attrib['operationDirection']
operationType = xmlGroup.attrib['operationType']
releaseTime = xmlGroup.attrib['releaseTime']
closeTime = xmlGroup.attrib['closeTime']
if operationType != 'AGENCY':
maturityRangeStart = dateutil.parser.parse(xmlGroup.attrib['maturityRangeStart'])
maturityRangeEnd = dateutil.parser.parse(xmlGroup.attrib['maturityRangeEnd'])
else:
maturityRangeStart = None
maturityRangeEnd = None
numIssues = len(list(xmlGroup)) - 2
totalAccepted = float(list(xmlGroup)[-2].getchildren()[0].attrib['value'])
totalSubmitted = float(list(xmlGroup)[-1].getchildren()[0].attrib['value'])
pomoData.append((operationDate, operationDirection, operationType, releaseTime, closeTime, maturityRangeStart, maturityRangeEnd, numIssues, totalAccepted, totalSubmitted))
w = csv.writer(open("pomo_{0}.csv".format(rangeString), 'w'))
w.writerows(pomoData)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment