myGetSymbols: An improved version of function 'getSymbols' from quantmod

Description Usage Arguments Value See Also Examples

View source: R/myGetSymbols.R

Description

This is a helper function to BatchGetSymbols and it should normaly not be called directly. The purpose of this function is to download financial data based on a ticker and a time period. The main difference from getSymbols is that it imports the data as a dataframe with proper named columns and saves data locally with the caching system.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
myGetSymbols(
  ticker,
  i.ticker,
  length.tickers,
  src = "yahoo",
  first.date,
  last.date,
  do.cache = TRUE,
  cache.folder = file.path(tempdir(), "BGS_Cache"),
  df.bench = NULL,
  be.quiet = FALSE,
  thresh.bad.data
)

Arguments

ticker

A single ticker to download data

i.ticker

A index for the stock that is downloading (for cat() purposes)

length.tickers

total number of stocks being downloaded (also for cat() purposes)

src

The source of the data ('google' or'yahoo')

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)

do.cache

Use cache system? (default = TRUE)

cache.folder

Where to save cache files? (default = file.path(tempdir(), 'BGS_Cache') )

df.bench

Data for bechmark ticker

be.quiet

Logical for printing statements (default = FALSE)

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)

Value

A dataframe with the financial data

See Also

getSymbols for the base function

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
ticker <- 'FB'

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

## Not run: 
df.ticker <- myGetSymbols(ticker,
                          first.date = first.date,
                          last.date = last.date)

## End(Not run)

Example output

Loading required package: rvest
Loading required package: xml2

Thank you for using BatchGetSymbols! If applicable, please use the following citation in your research report. Thanks! 

APA:
 Perlin, M. (2016) BatchGetSymbols: Downloads and Organizes Financial Data for Multiple Tickers. CRAN Package, Available in https://CRAN.R-project.org/package=BatchGetSymbols. 

BIBTEX:
 @misc{perlin2016batchgetsymbols,
  title = {BatchGetSymbols: Downloads and Organizes Financial Data for Multiple Tickers},
  author = {Marcelo Perlin},
  year = {2016},
  journal = {CRAN Package},
  url = {https://CRAN.R-project.org/package=BatchGetSymbols}
}

BatchGetSymbols documentation built on Jan. 13, 2021, 5:17 p.m.