get_col: Extract columns of data from _OHLC_ time series using column...

Description Usage Arguments Details Value Examples

View source: R/rutils.R

Description

Extract columns of data from OHLC time series using column field names.

Usage

1
get_col(oh_lc, field_name = "Close", data_env = NULL)

Arguments

oh_lc

An OHLC time series in xts format, or a vector of character strings with the names of OHLC time series.

field_name

A vector of strings with the field names of the columns to be be extracted (default is "Close").

data_env

The environment containing OHLC time series (default is NULL).

Details

The function get_col() extracts columns from OHLC time series and binds them into a single xts time series. get_col() can extract columns from a single xts time series, or from multiple time series.

The function get_col() extracts columns by partially matching field names with column names. The OHLC column names are assumed to be in the format "symbol.field_name", for example "VTI.Close".

In the simplest case when oh_lc is a single xts time series and field_name is a single string, the function get_col() performs a similar operation to the extractor functions Op(), Hi(), Lo(), Cl(), and Vo(), from package quantmod. But get_col() is able to handle symbols like LOW, which the function Lo() can't handle. The field_name argument is partially matched, for example "Vol" is matched to Volume (but it's case sensitive).

In the case when oh_lc is a vector of strings with the names of OHLC time series, the function get_col() reads the OHLC time series from the environment data_env, extracts the specified columns, and binds them into a single xts time series.

Value

The specified columns of the OHLC time series bound into a single xts time series, with the same number of rows as the input time series.

Examples

1
2
3
4
5
6
7
8
9
# get close prices for VTI
rutils::get_col(rutils::etf_env$VTI)
# get volumes for VTI
rutils::get_col(rutils::etf_env$VTI, field_name="Vol")
# get close prices and volumes for VTI
rutils::get_col(rutils::etf_env$VTI, field_name=c("Cl", "Vol"))
# get close prices and volumes for VTI and IEF
rutils::get_col(oh_lc=c("VTI", "IEF"), field_name=c("Cl", "Vol"),
  data_env=rutils::etf_env)

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