stockDataDownload {portfolioBacktest}R Documentation

Download stock data from the Internet

Description

This function is basically a robust wrapper for quantmod:getSymbols to download stock data from the internet. It will return 6 xts objects of the same dimensions named 'open', 'high', 'low', 'close', 'volume', 'adjusted' and 'index'. Additionally, it can return an xts object with an index. If the download for some stock fails after a few attempts they will be ignored and reported. Also, stocks with missing values can be optionally removed.

Usage

stockDataDownload(
  stock_symbols,
  index_symbol = NULL,
  from,
  to,
  rm_stocks_with_na = TRUE,
  local_file_path = getwd(),
  ...
)

Arguments

stock_symbols

String vector containing the symbols of the stocks to be downloaded. User can pass the market index symbol as its attribute 'index_symbol“ (only considered when argument 'index_symbol' is not passed).

index_symbol

String of the market index symbol.

from

String as the starting date, e.g., "2017-08-17".

to

String as the ending date (not included), e.g., "2017-09-17".

rm_stocks_with_na

Logical value indicating whether to remove stocks with missing values (ignoring leading missing values). Default is TRUE.

local_file_path

Path where the stock data will be saved after the first time is downloaded, so that in future retrievals it will be locally loaded (if the same arguments are used). Default is getwd(). If local caching is not desired, it can be deactivated by setting local_file_path = NULL.

...

Additional arguments to be passed to quantmod:getSymbols.

Value

List of 7 xts objects named 'open', 'high', 'low', 'close', 'volume', 'adjusted' and 'index'. Note that 'index' will only be returned when correct index symbols is passed.

Author(s)

Rui Zhou and Daniel P. Palomar

See Also

financialDataResample

Examples

## Not run: 
library(portfolioBacktest)
data(SP500_symbols)

# download data from internet
SP500_data <- stockDataDownload(stock_symbols = SP500_symbols,
                                from = "2009-01-01", to = "2009-12-31")

## End(Not run)


[Package portfolioBacktest version 0.4.1 Index]