0

嗨,我正在尝试使用 R edgar 包读取 SEC edgar 数据库中的 13F 文件

我面临的挑战是我正在查看的文件是旧文件(~2000 年) https://www.sec.gov/edgar/browse/?CIK=1087699

它们是糟糕的 txt 格式,与今天的 13F 不同,并且使用 readtxt 函数无法读取。

示例文件在这里:https ://www.sec.gov/Archives/edgar/data/1087699/000108769999000001/0001087699-99-000001.txt

library(edgar)

F13<-
  getFilings(
  cik.no = "0001087699",
  form.type = "13F-HR",
  1999,
  quarter=c(1,2,3),
  useragent="myname@gmail.com"
)

我试过了,R 只是告诉我它很忙并且永远下载,它不是一个很大的 txt 文件。所以出了点问题。然后当它最终完成时,它说没有找到给定 CIK 和表单类型的归档信息,但我清楚地在查看文件。如果 edgar 包没有设计来处理它,那我该怎么办呢?

我的最终目标是将文件保存在漂亮的数据框中,股票代码和价格的列以及股票数据的行。请帮忙。

有没有可用的刮痧?我通过检查铬突出了灯光,但它们对我来说看起来很奇怪(抱歉,根本不擅长)。

4

2 回答 2

1

我在这里解析了您作为示例提供的文件。我首先将数据从文件复制到一个txt文件。该文件copied.txt需要位于当前工作目录中。这可以让你知道如何进行。

library(tidyverse)

df <- read_file("copied.txt") %>%
  # trying to extract data only from the table
  (function(x){
    tbl_beg <- str_locate(x, "Managers Sole")[2] + 1
    tbl_end <- str_locate(x, "\r\n</TABLE>")[1]
    str_sub(x, tbl_beg, tbl_end)
    }) %>%
  # removing some unwanted characters from the beginning and the end of the extracted string
  str_sub(start = 4, end = -3) %>%
  # splitting for individual lines
  str_split('\"\r\n\"') %>% unlist() %>%
  # removing broken line break
  str_remove("\r\n") %>%
  # replacing the original text where there are spaces with one, where there is underscore
  # the reason for that is that I need to split the rows into columns using space
  str_replace_all("Sole   Managers Sole", " Managers_Sole") %>%
  # removing extra spaces
  str_squish() %>%
  # reversing the order of the line (I need to split from the right because the company name contains additional spaces)
  # if the company name is the last one, it is okey that there are additional spaces
  stringi::stri_reverse() %>%
  str_split(pattern = " ", n = 6, simplify = T) %>%
  # making the order to the original one
  apply(MARGIN = 2, FUN = stringi::stri_reverse) %>%
  as_tibble() %>%
  select(c(6:1)) %>%
  set_names(nm = c("name_of_issuer", "title_of_cl", "cusip_number", "fair_market_value", "shares",  "shares_of_princip_mngrs"))

# A tibble: 47 x 6
   name_of_issuer   title_of_cl cusip_number fair_market_value shares  shares_of_princip_mngrs
   <chr>            <chr>       <chr>        <chr>             <chr>   <chr>                  
 1 America Online   COM         02364J104    2,940,000         20,000  Managers_Sole          
 2 Anheuser Busch   COM         35229103     3,045,000         40,000  Managers_Sole          
 3 At Home          COM         45919107     787,500           5,000   Managers_Sole          
 4 AT&T             COM         1957109      5,985,937         75,000  Managers_Sole          
 5 Bank Toyko       COM         65379109     700,000           50,000  Managers_Sole          
 6 Bay View Capital COM         07262L101    14,958,437        792,500 Managers_Sole          
 7 Broadcast.com    COM         111310108    2,954,687         25,000  Managers_Sole          
 8 Chase Manhattan  COM         16161A108    10,578,750        130,000 Managers_Sole          
 9 Chase Manhattan  4/85C       16161A9DQ    59,375            500     Managers_Sole          
10 Cisco Systems    COM         17275R102    4,930,312         45,000  Managers_Sole    
于 2021-10-12T12:59:28.160 回答
0

您可以使用httr包来请求页面:

> install.packages("httr")
# follow instructions etc

然后在Rshell 中(您可能需要重新启动):

> httr::GET("https://www.sec.gov/Archives/edgar/data/1087699/000108769999000001/0001087699-99-000001.txt")

这将成功下载文件,但是我在 R 中不够流利,无法解析此文本,但它看起来很简单:将文本拆分<TABLE>为 ,为行添加样条换行符,将每一行拆分为列的空格。

于 2021-10-11T09:21:25.347 回答