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

View source: R/rutils.R

get_dataR Documentation

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

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

get_data(
  symbolv,
  data_dir = NULL,
  data_env,
  startd = "2007-01-01",
  endd = Sys.Date(),
  func = match.fun("as.Date"),
  formatv = "%Y-%m-%d",
  header = TRUE,
  echo = TRUE,
  scrub = TRUE
)

Arguments

symbolv

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.

startd

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

endd

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

func

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

formatv

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).

echo

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 symbolv.

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 startd and endd must be either of class Date, or a string in the format "YYYY-mm-dd".

Value

A vector of symbolv returned invisibly.

Examples

## Not run: 
new_env <- new.env()
# Load prices from local csv files
rutils::get_data(symbolv=c("SPY", "EEM"),
            data_dir="C:/Develop/data/bbg_records",
            data_env=new_env)
# Download prices from YAHOO
rutils::get_data(symbolv=c("MSFT", "XOM"),
            data_env=new_env,
            startd="2012-12-01",
            endd="2015-12-01")

## End(Not run)

algoquant/rutils documentation built on April 18, 2024, 12:05 a.m.