BatchGetSymbols: Function to download financial data

Description Usage Arguments Value Warning See Also Examples

View source: R/BatchGetSymbols.R

Description

This function is designed to make batch downloads of financial data using getSymbols. Based on a set of tickers and a time period, the function will download the data for each ticker and return a report of the process, along with the actual data in the long dataframe format. The main advantage of the function is that it automatically recognizes the source of the dataset from the ticker and structures the resulting data from different sources in the long format. A caching system is also presente, making it very fast.

Usage

1
2
3
4
5
BatchGetSymbols(tickers, first.date = Sys.Date() - 30,
  last.date = Sys.Date(), thresh.bad.data = 0.75,
  bench.ticker = "^GSPC", type.return = "arit", freq.data = "daily",
  do.complete.data = FALSE, do.cache = TRUE,
  cache.folder = "BGS_Cache")

Arguments

tickers

A vector of tickers. If not sure whether the ticker is available, check the websites of google and yahoo finance. The source for downloading the data can either be Google or Yahoo. The function automatically selects the source webpage based on the input ticker.

first.date

The first date to download data (date or char as YYYY-MM-DD)

last.date

The last date to download data (date or char as YYYY-MM-DD)

thresh.bad.data

A percentage threshold for defining bad data. The dates of the benchmark ticker are compared to each asset. If the percentage of non-missing dates with respect to the benchmark ticker is lower than thresh.bad.data, the function will ignore the asset (default = 0.75)

bench.ticker

The ticker of the benchmark asset used to compare dates. My suggestion is to use the main stock index of the market from where the data is coming from (default = ^GSPC (SP500, US market))

type.return

Type of price return to calculate: 'arit' (default) - aritmetic, 'log' - log returns.

freq.data

Frequency of financial data ('daily', 'weekly', 'monthly', 'yearly')

do.complete.data

Return a complete/balanced dataset? If TRUE, all missing pairs of ticker-date will be replaced by NA (default = FALSE)

do.cache

Use caching system? (default = TRUE)

cache.folder

Where to save cache files? (default = 'BGS_Cache')

Value

A list with the following items:

df.control

A dataframe containing the results of the download process for each asset

df.tickers

A dataframe with the financial data for all valid tickers

Warning

Do notice that adjusted prices are not available from google finance. When using this source, the function will output NA values for this column.

See Also

getSymbols

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
tickers <- c('FB','NYSE:MMM')

first.date <- Sys.Date()-30
last.date <- Sys.Date()

l.out <- BatchGetSymbols(tickers = tickers,
                         first.date = first.date,
                        last.date = last.date, do.cache=FALSE)

print(l.out$df.control)
print(l.out$df.tickers)

BatchGetSymbols documentation built on Oct. 11, 2018, 5:05 p.m.