get_data | R 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.
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
)
symbolv |
A vector of strings representing instrument symbols (tickers). |
data_dir |
The directory containing CSV files (default is
|
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
|
func |
The name of the function for formatting the date
fields in the CSV files (default is |
formatv |
The format of the date fields in the CSV files
(default is |
header |
A Boolean argument: if |
echo |
A Boolean argument: if |
scrub |
A Boolean argument: if |
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".
A vector of symbolv
returned invisibly.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.