tidyquant (version 0.5.1)

tq_get: Get quantitative data in tibble format

Description

Get quantitative data in tibble format

Usage

tq_get(x, get = "stock.prices", complete_cases = TRUE, ...)

tq_get_options()

tq_get_stock_index_options()

Arguments

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 x. Options include:

  • "stock.prices": Get the open, high, low, close, volume and adjusted stock prices for a stock symbol from Yahoo Finance. Wrapper for quantmod::getSymbols().

  • "stock.prices.japan": Get the open, high, low, close, volume and adjusted stock prices for a stock symbol from Yahoo Finance Japan. Wrapper for quantmod::getSymbols.yahooj().

  • "financials": Get the income, balance sheet, and cash flow financial statements for a stock symbol from Google Finance. Wrapper for quantmod::getFinancials().

  • "key.ratios": Get 89 historical growth, profitablity, financial health, efficiency, and valuation ratios that span 10-years from Morningstar.

  • "key.stats": Get 55 real-time key statistics such as Ask, Bid, Day's High, Day's Low, Last Trade Price, current P/E Ratio, EPS, Market Cap, EPS Projected Current Year, EPS Projected Next Year and many more from Yahoo Finance.

  • "dividends": Get the dividends for a stock symbol from Yahoo Finance. Wrapper for quantmod::getDividends().

  • "splits": Get the splits for a stock symbol from Yahoo Finance. Wrapper for quantmod::getSplits().

  • "economic.data": Get economic data from FRED. rapper for quantmod::getSymbols.FRED().

  • "metal.prices": Get the metal prices from Oanda. Wrapper for quantmod::getMetals().

  • "exchange.rates": Get exchange rates from Oanda. Wrapper for quantmod::getFX().

  • "quandl": Get data sets from Quandl. Wrapper for Quandl(). See also quandl_api_key().

  • "quandl.datatable": Get data tables from Quandl. Wrapper for Quandl.datatable(). See also quandl_api_key().

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. TRUE by default, and a warning message is generated for any rows removed.

...

Additional parameters passed to the "wrapped" function. Investigate underlying functions to see full list of arguments. Common optional parameters include:

  • from: Optional for various time series functions in quantmod / quandl packages. A character string representing a start date in YYYY-MM-DD format. No effect on "financials", "key.ratios", or "key.stats".

  • to: Optional for various time series functions in quantmod / quandl packages. A character string representing a end date in YYYY-MM-DD format. No effect on get = "financials", "key.ratios", or "key.stats".

Value

Returns data in the form of a tibble object.

Details

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.

See Also

  • 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.

Examples

Run this code
# NOT RUN {
# Load libraries
library(tidyquant)

# 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", "financials"),
                    from = "2016-01-01",
                    to   = "2017-01-01")
# }

Run the code above in your browser using DataLab