get_data: Load _OHLC_ time series data into an environment, either from...

Description Usage Arguments Details Value Examples

View source: R/rutils.R

Description

Load OHLC time series data into an environment, either from an external source (download from YAHOO), or from CSV files in a local drive.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
get_data(
  sym_bols,
  data_dir = NULL,
  data_env,
  start_date = "2007-01-01",
  end_date = Sys.Date(),
  date_fun = match.fun("as.Date"),
  for_mat = "%Y-%m-%d",
  header = TRUE,
  e_cho = TRUE,
  scrub = TRUE
)

Arguments

sym_bols

A vector of strings representing instrument symbols (tickers).

data_dir

The directory containing CSV files (default is NULL).

data_env

The environment for loading the data into.

start_date

The start date of time series data (default is "2007-01-01").

end_date

The end date of time series data (default is Sys.Date()).

date_fun

The name of the function for formatting the date fields in the CSV files (default is as.Date()).

for_mat

The format of the date fields in the CSV files (default is %Y-%m-%d).

header

A Boolean argument: if TRUE then read the header in the CSV files (default is TRUE).

e_cho

A Boolean argument: if TRUE then print to console information on the progress of CSV file loading (default is TRUE).

scrub

A Boolean argument: if TRUE then remove NA values using function rutils::na_locf() (default is TRUE).

Details

The function get_data() loads OHLC time series data into an environment (as a side-effect), and returns invisibly the vector of sym_bols.

If the argument data_dir is specified, then get_data() loads from CSV files in that directory, and overwrites NA values if scrub=TRUE. If the argument data_dir is not specified, then get_data() downloads adjusted OHLC prices from YAHOO.

The function get_data() calls the function getSymbols.yahoo() for downloading data from YAHOO, and performs a similar operation to the function getSymbols() from package quantmod. But get_data() is faster because it performs less overhead operations, and it's able to handle symbols like LOW, which getSymbols() can't handle because the function Lo() can't handle them. The start_date and end_date must be either of class Date, or a string in the format "YYYY-mm-dd".

Value

A vector of sym_bols returned invisibly.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## Not run: 
new_env <- new.env()
# Load prices from local csv files
rutils::get_data(sym_bols=c("SPY", "EEM"),
            data_dir="C:/Develop/data/bbg_records",
            data_env=new_env)
# Download prices from YAHOO
rutils::get_data(sym_bols=c("MSFT", "XOM"),
            data_env=new_env,
            start_date="2012-12-01",
            end_date="2015-12-01")

## End(Not run)

algoquant/rutils documentation built on Feb. 26, 2021, 1:30 a.m.