Skip to content

Instantly share code, notes, and snippets.

@natereed
Forked from ddd1600/CIKgetter.R
Created January 21, 2016 19:46
Show Gist options
  • Save natereed/e127f674af2b0202c4b1 to your computer and use it in GitHub Desktop.
Save natereed/e127f674af2b0202c4b1 to your computer and use it in GitHub Desktop.
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)
CIK
}
getCIK("AAPL")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment