mget_symbols: Get multiple symbols and store in a single xts matrix

Description Usage Arguments Details Value Examples

Description

This function uses quantmod getSymbols to download multiple symbols from a data source. It then extracts one set of values (column) from the OHLC data for each symbol and stores it into a wide xts matrix for easy reference. Proper data columns are selected by invoking the appropriate function from OHLC.Transformations in quantmod.

Usage

1
2
mget_symbols(symbols, from = "1999-01-01", OHLC = "Ad",
  src = "yahoo", filepath = "../DATABASE/data", locf = TRUE, ...)

Arguments

symbols

A vector of symbol names to download (character vector).

from

The start date from which the data is downloaded.

OHLC

Specifies the value to be extracted from the OHLC data. The default is "Ad" for adjusted close. Must be one of c("Ad", "Cl", "Op", "Hi", "Lo")

src

Source where to find the data. If src = "database", then the symbol is searched in the local database with path as specified in argument filepath. Otherwise, this is passed to quantmod::getSymbols function.

filepath

The file path where to find the local database. Default is: "../DATABASE/data". This is used only if src = "database". In that case, a file name will automatically be created consisting of the symbol string concatenated with ".csv".

locf

Last observation carried forward. When TRUE, the resulting prices matrix is subjected to function na.locf to carry forward the last observation and therefore eliminate any NAs in the price matrix. This is relevant when some prices are available at different days than others and NAs are introduced within the matrix (beyond the beginning of the time series). If these NAs are not eliminated, then computing returns from the matrix will produce some NA returns and therefore some information will be lost, creating an incomplete equity curve. Subjecting the matrix to na.locf addresses this issue. Default is TRUE.

...

Additional arguments passed to quantmod::getSymbols

Details

For example, if value = "Cl", then quantmod::Cl() function is invoked to extract the Close column for each symbol.

If a symbol does not have enough history, leading NAs are introduced for that symbol. If the startdate provided is earlier than all dates when symbol data is available, then theses dates are omitted.

Value

Returns an xts matrix starting at startdate or later if no symbol data is available at the earlier dates.

Examples

1
2
3
4
x <- mget_symbols(c('SPY', 'QQQ', 'EWC', 'GLD'), startdate="1999-03-01")
head(x, 15)
y <- mget_symbols(c('SPY', 'QQQ', 'EWC', 'GLD'), startdate="1999-03-01", OHLC="Cl")
head(y, 15)

jeanmarcgp/xtsanalytics documentation built on May 19, 2019, 12:38 a.m.