-
-
Save ddd1600/3934032 to your computer and use it in GitHub Desktop.
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") |
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"
is there a way to do Opposite. by feeding the CIK to the function and have it return the TradingSymbol ???
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
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)
According to Arconic's website, Arconic (ARNC) was "launched" as a standalone company by Alcoa (AA) in 2016 (Alcoa basically split into two companies: Alcoa and Arconic). Arconic further split into two companies in 2020: Arconic and Howmet Aerospace. Apparently, Arconic kept at least one identifier previously associated solely with Alcoa after 2016.
This is where the commercial market data providers earn their keep. Stock market data maintenance is a very important issue. Name, ticker, CUSIP, CIK, etc. changes must be tracked and adjusted for daily. Here's something I wrote about it in 2009:
"If you are maintaining a historical database, you need to have a way to "archive" companies that "die" so you'll retain the data. You also need to be able to track name/ticker changes and splits so you can maintain consistency through time and link the correct data with the correct company at any point in time.
For example, consider AT&T (T) and SBC Communications (SBC). In 2005, SBC acquired T, but took the AT&T name and ticker. So, the pre-merger AT&T (T) "died" and the post-merger AT&T (T) was the combined entity SBC/AT&T.
In 2006, T and Bell South (BLS) merged, keeping the T name and ticker. So, the pre-merger BLS "died" and the post-merger AT&T is the combined entity SBC/T/BLS.
So, there are actually two different entities associated with the name AT&T: one which "died" in 2005 when acquired by SBC, and the "other" one today, which is actually the combined entities SBC/T/BLS which was renamed AT&T after the SBC acquisition.
Track the history for Wachovia and you'll find a similar situation: Fleet Bank acquired Wachovia but kept the Wachovia name (so, there was an "old" Wachovia which "died" and a "new" Wachovia--which was the combined entities Fleet and Wachovia), then Wells Fargo acquired Wachovia (so, now there are two "old" Wachovias that are "dead")."
So the fact that names, tickers, etc. are sometimes reused by totally different entities over time greatly complicates maintaining historical market data.
sometime an error occurs
Error in UseMethod("getSibling") :
no applicable method for 'getSibling' applied to an object of class "NULL"
Here is the html:
Click on CIK to view company filings
Items 1 - 2
formerly: YORK CAPITAL MANAGEMENT L P /NY/ (filings through 2009-03-18)