Skip to content

Instantly share code, notes, and snippets.

@ddd1600
Created October 22, 2012 20:39
Show Gist options
  • Save ddd1600/3934032 to your computer and use it in GitHub Desktop.
Save ddd1600/3934032 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")
@iangow
Copy link

iangow commented Jun 8, 2013

require(XML)
require(RCurl)

@dougvk
Copy link

dougvk commented Jan 19, 2014

for those looking for a python implementation: https://gist.github.com/dougvk/8499335

@nickkraakman
Copy link

Can also use the iEDGAR API (PHP example): https://gist.github.com/kregus/e0bc5be2502007bc7f56

A complete Ticker to CIK mapping can be found as a CSV file here: https://www.valuespreadsheet.com/iedgar

Rank & Filed also offers a similar Ticker to CIK mapping in CSV here:
http://rankandfiled.com/#/data/tickers

@adrfinance
Copy link

@Kregus the list you provided by Rank & Filed (http://rankandfiled.com/#/data/tickers) is awesome! Thanks a lot!

@efaysal
Copy link

efaysal commented Feb 18, 2016

sometime an error occurs
Error in UseMethod("getSibling") :
no applicable method for 'getSibling' applied to an object of class "NULL"

Here is the html:

Companies with names matching "YORK CAPITAL MANAGEMENT"
Click on CIK to view company filings
Items 1 - 2
CIK Company State/Country
0001480532 York Capital Management Global Advisors, LLC NY
0000879074 YORK CAPITAL MANAGEMENT L P
formerly: YORK CAPITAL MANAGEMENT L P /NY/ (filings through 2009-03-18)
NY

@ZeccaLehn
Copy link

ZeccaLehn commented Nov 8, 2017

Looks like the SEC changed the site address to an https. The above wasn't working with http:

require(XML)
require(RCurl)

getCIK = function(ticker) {
  stopifnot(is.character(ticker))
  uri = "https://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("GE")
# "40545"

@jells09
Copy link

jells09 commented Jun 24, 2018

is there a way to do Opposite. by feeding the CIK to the function and have it return the TradingSymbol ???

@ColonelBuendia
Copy link

ColonelBuendia commented Jun 12, 2019

yes, using the mapping table they provide. Bash/awk implementation below as reference.

curl -sL https://www.sec.gov/include/ticker.txt | sort > tickercik.txt
awk '$2=="yourcik"{print $1}' tickercik.txt

@SteveBronder
Copy link

fyi I'm seeing things that don't match up in the Rank and Filed data http://rankandfiled.com/#/data/tickers

for instance Aloca Inc (AA) on the SEC site has cik code 1675149 but on rank and filed it's 4281. 4281 matches up with Arconic Inc (ARNC)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment