Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #einhorn_13F_2016.R
  2. # Holdings of D. Einhorns Hedge Fund
  3. # Metadata / Background Info
  4. #https://www.sec.gov/Archives/edgar/data/1079114/000107911416000025/xslForm13F_X01/primary_doc.xml
  5. library(ggplot2)
  6. library(rvest)
  7. library(stringi)
  8. library(purrr)
  9. library(tidyr)
  10. library(dplyr)
  11.  
  12. # data
  13. # read in HTML:
  14. html_url <- "https://www.sec.gov/Archives/edgar/data/1079114/000107911416000025/xslForm13F_X01/Greenlight_13FXML_06302016.xml"
  15. html_dat <- read_html(html_url)
  16.  
  17. #find the right table in HTML DOM
  18. html_dat <- html_table(html_dat, header = TRUE, fill=TRUE)[[4]]
  19. glimpse(html_dat)
  20.  
  21. # parse messed-up table header
  22. einhorn_col <- map2_chr(html_dat[1,],html_dat[2,], paste)
  23. einhorn <- html_dat
  24. colnames(einhorn) <- make.names(stri_trim(stringi::stri_trans_tolower(paste0( einhorn_col, sep=""))))
  25. einhorn <- einhorn[3:nrow(einhorn),]
  26.  
  27. # there are 2 important numeric columns
  28. einhorn[, "value..x.1000."] <- as.numeric(gsub(",", "",einhorn[, "value..x.1000."]))
  29. einhorn[, "shrs.or.prn.amt"] <- as.numeric(gsub(",", "", einhorn[, "shrs.or.prn.amt"]))
  30.  
  31. # most important holdings by value
  32. einhorn %>%
  33. group_by(name.of.issuer) %>%
  34. summarise(sum_value=sum(value..x.1000.),sum_shares=sum(shrs.or.prn.amt)) %>%
  35. arrange(desc(sum_value))
  36.  
  37. # show some company names
  38. companies <- unique(einhorn$name.of.issuer)
  39. sample(companies, 6)
  40.  
  41. colnames(einhorn)
  42. [1] "name.of.issuer" "title.of.class" "cusip"
  43. [4] "value..x.1000." "shrs.or.prn.amt" "sh..prn"
  44. [7] "put..call" "investment.discretion" "other.manager"
  45. [10] "voting.authority.sole" "voting.authority.shared" "voting.authority.none"
  46.  
  47. company CIK SIC state state.inc FY.end street.address city.state
  48. 1 GOOGLE INC. 0001288776 7370 CA DE 1231 1600 AMPHITHEATRE PARKWAY MOUNTAIN VIEW CA 94043
  49.  
  50. sample(companies, 6)
  51. [1] "TAKE-TWO INTERACTIVE SOFTWAR" "TERRAFORM PWR INC"
  52. [3] "APPLE INC" "VOYA FINL INC"
  53. [5] "AERCAP HOLDINGS NV" "PERRIGO CO PLC
  54.  
  55. finreportr::CompanyInfo("TERRAFORM PWR INC")
  56.  
  57. Error in open.connection(x, "rb") : HTTP error 400.
  58. Calls: <Anonymous> -> <Anonymous> -> read_html.default
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement