Learn R Programming

tidyquant (version 0.3.0)

tq_get: Get quantitative data in tibble format

Description

Get quantitative data in tibble format

Usage

tq_get(x, get = "stock.prices", ...)
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 index, 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.index": Get all stock symbols in any of 18 stock indexes from marketvolume.com.
  • "stock.prices": Get the open, high, low, close, volumen and adjusted stock prices for a stock symbol from Yahoo Finance.
  • "financials": Get the income, balance sheet, and cash flow financial statements for a stock symbol from Google Finance.
  • "key.ratios": These are key historical ratios. Get 89 historical growth, profitablity, financial health, efficiency, and valuation ratios that span 10-years from morningstar.com.
  • "key.stats": These are key current statistics. Get 55 current 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.
  • "splits": Get the splits for a stock symbol from Yahoo Finance.
  • "economic.data": Get economic data from FRED.
  • "metal.prices": Get the metal prices from Oanda.
  • "exchange.rates": Get exchange rates from Oanda.
...
Additional parameters passed to the appropriate quantmod function. Common optional parameters include:
  • from: Optional. A character string representing a start date in YYYY-MM-DD format. No effect on get = "stock.index", "financials", or "key.ratios".
  • to: A character string representing a end date in YYYY-MM-DD format. No effect on get = "stock.index", get = "financials", or "key.ratios".
  • use_fallback: Used with get = "stock.index" only. Set to FALSE by default. A boolean representing whether to use the fall back data set for a stock index. Useful if the data cannot be fetched from the website. The fallback data returned is accurate as of the date the package was last updated.

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. 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() returns a list of stock indexes you can choose from. Alternatively tq_get("options", get = "stock.index") can be used.

Examples

Run this code
# Load libraries
library(tidyquant)

##### Basic Functionality

# Get the list of `get` options
tq_get_options()

# Get all stocks in a stock index from www.marketvolume.com
tq_get_stock_index_options() # Get stock index options
tq_get("SP500", get = "stock.index")

# 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")

Run the code above in your browser using DataLab