Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the fastest and/or better way to use getSymbols()? To get each equity separate or all together?

Tags:

r

quantmod

Let's assume that you would like to get the data from a lot of equities (>100) from Yahoo and Alpha Vantage (AV) since 2000.

I was wondering if somebody did investigate any of the following 2 questions:

1) What is faster when using getSymbols()? To get each equity separate or all together in one call to getSymbols()?

2) What would be less error prone? Separate calls or one call with all the equities?

Thanks for any help or suggestion in any of the 2 points.

HL

like image 389
H.L. Avatar asked Oct 15 '18 12:10

H.L.


People also ask

What does getSymbols do?

getSymbols is a wrapper to load data from various sources, local or remote. Data is fetched via one of the available getSymbols methods and either saved in the env specified - the parent. frame() by default -- or returned to the caller.

What is quantmod in R?

“The quantmod package for R is designed to assist the quantitative trader in the development, testing, and deployment of statistically based trading models.” It is a rapid prototyping environment where enthusiasts can explore various technical indicators with minimum effort.

What is the R package for downloading data from Yahoo Finance?

BatchGetSymbols is a R package for large-scale download of financial data from Yahoo Finance. Based on a set of tickers and date ranges, the package will download and organize the financial data in the tidy/long format.

How do I download stock prices in R?

You can install it by typing the command install. packages("quantmod") in your R console. The prices downloaded in by using quantmod are xts zoo objects. For our calculations we will use tidyquant package which downloads prices in a tidy format as a tibble .


1 Answers

Why not something like the following which will drag in the whole SP500, then you can just filter by ticker.

library(BatchGetSymbols)

first.date <- Sys.Date()-365
last.date <- Sys.Date()

df.SP500 <- GetSP500Stocks()
tickers <- df.SP500$tickers

l.out <- BatchGetSymbols(tickers = tickers,
                         first.date = first.date,
                         last.date = last.date)

print(l.out$df.control)
print(l.out$df.tickers)

df <- l.out$df.control
df2 <- l.out$df.tickers

library(tidyquant)
df2 %>% 
  filter(ticker == "GOOG") %>%
  ggplot(aes(x = ref.date, y = price.close)) +
  geom_line() +
  labs(title = "GOOG Line Chart", y = "Closing Price", x = "") + 
  theme_tq()

I am sure tidyquant has a function to grab the whole SP500 also.

like image 164
user113156 Avatar answered Oct 21 '22 15:10

user113156