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,
  datadir = NULL,
  datenv,
  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).

datadir

The directory containing CSV files (the default is NULL).

datenv

The environment for loading the data into.

startd

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

endd

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

func

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

formatv

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

header

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

echo

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

scrub

A Boolean argument: if TRUE then remove NA values using function rutils::nalocf() (the 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 datadir is specified, then get_data() loads from CSV files in that directory, and overwrites NA values if scrub=TRUE. If the argument datadir 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: 
newenv <- new.env()
# Load prices from local csv files
rutils::get_data(symbolv=c("SPY", "EEM"),
            datadir="C:/Develop/data/bbg_records",
            datenv=newenv)
# Download prices from YAHOO
rutils::get_data(symbolv=c("MSFT", "XOM"),
            datenv=newenv,
            startd="2012-12-01",
            endd="2015-12-01")

## End(Not run)

algoquant/rutils documentation built on June 10, 2025, 3:55 p.m.