I'm struggling to download the stock price in R.
Here are my questions.
- I used getMasterIndex to download the MasterIndex of all SEC filings and filter 10-k reports (I only need 10-k reports for analysis)
- I need to use the company.name from the MasterIndex to download the stock price for each company at the previous day of filing date (which means I need to get the stock price for companies at different dates). But I failed by using the getSymbol function since it requires tickers instead of company names. So I need to first transfer the company.name to tickers? and then download the stock price based on the corresponding (filing date-1)?
But is there any way to directly download the stock price from the company.name of MasterIndex? I attached the previous code and the getsymbol code below. Please help me out of this problem. Much thanks!
master_indexes <- list.files("Master Indexes/",pattern="Rda")
all_indexes <- data.frame()
for(master_index in master_indexes){
load(paste0("Master Indexes/",master_index))
this_index <- year.master
all_indexes <- bind_rows(all_indexes,this_index)
print(master_index)
}
head(all_indexes)
company_filing_info <- all_indexes %>%
filter(form.type =="10-K")
companies <- company_filing_info$company.name
library(tidyquant)
for (i in companies) {
getSymbols(companies,
src = "yahoo",
auto.assign = TRUE)
}
A possible solution. The issue is that the way
edgaroutput company names is different from others for some reason.My example data with SEC Filings in 2022
Now, download the
.Rdatafrom my Drive will give you a data frame of stocks, which has company names and their respective tickersMerge
stockswithdf