| tq_get {tidyquant} | R Documentation |
tibble formatGet quantitative data in tibble format
tq_get(x, get = "stock.prices", complete_cases = TRUE, ...) tq_get_options() tq_get_stock_index_options()
x |
A single character string, a character vector or tibble representing a single (or multiple) stock symbol, metal symbol, currency combination, FRED code, etc. |
get |
A character string representing the type of data to get
for
|
complete_cases |
Removes symbols that return an NA value due to an error with the get
call such as sending an incorrect symbol "XYZ" to get = "stock.prices". This is useful in
scaling so user does not need to
add an extra step to remove these rows. |
... |
Additional parameters passed to the "wrapped" function. Investigate underlying functions to see full list of arguments. Common optional parameters include:
|
tq_get() is a consolidated function that gets data from various
web sources. The function is a wrapper for several quantmod
functions, Quandl functions, and also gets data from websources unavailable
in other packages.
The results are always returned as a tibble. The advantages
are (1) only one function is needed for all data sources and (2) the function
can be seemlessly used with the tidyverse: purrr, tidyr, and
dplyr verbs.
tq_get_options() returns a list of valid get options you can
choose from.
tq_get_stock_index_options() Is deprecated and will be removed in the
next version. Please use tq_index_options() instead.
Returns data in the form of a tibble object.
tq_index() to get a ful list of stocks in an index.
tq_exchange() to get a ful list of stocks in an exchange.
quandl_api_key() to set the api key for collecting data via the "quandl"
get option.
av_api_key() to set the api key for collecting data via the "alphavantage"
get option.
# Load libraries
library(tidyquant)
library(dplyr)
# Get the list of `get` options
tq_get_options()
# Get stock prices for a stock from Yahoo
aapl_stock_prices <- tq_get("AAPL")
# Get stock prices for multiple stocks
mult_stocks <- tq_get(c("FB", "AMZN"),
get = "stock.prices",
from = "2016-01-01",
to = "2017-01-01")
# Multiple gets
mult_gets <- tq_get("AAPL",
get = c("stock.prices", "dividends"),
from = "2016-01-01",
to = "2017-01-01")