get_data function

Tools for Getting and Working with Data

Tools for Getting and Working with Data

Download (and possibly) merge data from freely available databases.

get_data(x, from = NULL, to = NULL, src = c("yahoo", "quandl", "oanda", "FRED", "google"), FUN = NULL, verbose = TRUE, warn = TRUE, ...)

Arguments

  • x: vector of ticker symbols (e.g. "^GSPC" if src = "yahoo" or "EUR/USD" if src = "oanda").

  • from: start date as a Date object or character string (in international date format "yyyy-mm-dd"); if NULL, the earliest date with available data is picked.

  • to: end date as a Date object or character string (in international date format "yyyy-mm-dd"); if NULL, the last date with available data is picked.

  • src: character string specifying the data source (e.g. "yahoo" for stocks or "oanda" for FX data); see getSymbols() and Quandl().

  • FUN: function to be applied to the data before being returned. This can be

    • the identity:: if the data could not be retrieved (and is thus replaced by NA);
    • the given FUN:: if FUN has been provided;
    • a useful default:: if FUN = NULL; the default uses the adjusted close price Ad() if src = "yahoo", the close price Cl() if src = "google" and the identity otherwise.
  • verbose: logical indicating whether progress monitoring should be done.

  • warn: logical indicating whether a warning is given showing the error message when fetching x fails.

  • ...: additional arguments passed to the underlying getSymbols() from quantmod or Quandl() from Quandl (if src = "quandl").

Returns

xts object containing the data with column name(s) adjusted to be the ticker symbol (in case lengths match; otherwise the column names are not adjusted); NA if data is not available.

Details

FUN is typically one of quantmod's Op, Hi, Lo, Cl, Vo, Ad or one of the combined functions OpCl, ClCl, HiCl, LoCl, LoHi, OpHi, OpLo, OpOp.

Author(s)

Marius Hofert

Examples

## Not run: ## Note: This needs a working internet connection ## Get stock and volatility data (for all available trading days) dat <- get_data(c("^GSPC", "^VIX")) # note: this needs a working internet connection ## Plot them (Alternative: plot.xts() from xtsExtra) library(zoo) plot.zoo(dat, screens = 1, main = "", xlab = "Trading day", ylab = "Value") ## End(Not run)
  • Maintainer: Marius Hofert
  • License: GPL (>= 3) | file LICENCE
  • Last published: 2024-03-04

Useful links