Skip to content

Instantly share code, notes, and snippets.

@ddd1600
ddd1600 / CIKgetter.R
Created October 22, 2012 20:39
get SEC CIK number from ticker symbol
getCIK = function(ticker) {
stopifnot(is.character(ticker))
uri = "http://www.sec.gov/cgi-bin/browse-edgar"
response = getForm(uri,CIK=ticker,action="getcompany")
html = htmlParse(response)
CIKNode = getNodeSet(html, "//acronym[@title=\"Central Index Key\"][text() = \"CIK\"]")
CIKNodeText = sapply(CIKNode, function(x) xmlValue(getSibling(getSibling(x))))
CIK = sub(" .*","",CIKNodeText)
CIK = sub("^0*","",CIK)