qrmtools (version 0.0-6)

get_data: Tools for Getting and Working with Data

Description

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

Usage

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

Arguments

x

A 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

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

FUN

A 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

A logical indicating whether progress monitoring should be done.

warn

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

Additional arguments passed to the underlying function getSymbols() from quantmod or Quandl() from Quandl (if src="quandl").

Value

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

Examples

Run this code
## 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")

Run the code above in your browser using DataCamp Workspace