chart_xts: Plot either a line plot or a candlestick plot of an _xts_...

Description Usage Arguments Details Value Examples

View source: R/rutils.R

Description

A wrapper for function chart_Series() from package quantmod.

Usage

1
chart_xts(x_ts, col_ors = NULL, ylim = NULL, in_dic = NULL, x_11 = TRUE, ...)

Arguments

x_ts

An xts time series or an OHLC time series.

col_ors

A vector of strings with the custom line colors.

ylim

A numeric vector with two elements containing the y-axis range.

in_dic

A Boolean vector or xts time series for specifying the shading areas, with TRUE indicating "lightgreen" shading, and FALSE indicating "antiquewhite" shading.

x_11

A Boolean argument: if TRUE then open x11 window for plotting, else plot in standard window (default is TRUE).

...

Additional arguments to function chart_Series().

Details

The function chart_xts() plots a line plot of a xts time series, or a candlestick plot if x_ts is a OHLC time series. The function chart_xts() plots with custom line colors and vertical background shading, using the function chart_Series() from package quantmod. By default chart_xts() opens and plots in an x11 window.

The function chart_xts() extracts the chart_Series() chart object and modifies its ylim parameter using accessor and setter functions. It also adds background shading specified by the in_dic argument, using function add_TA(). The in_dic argument should have the same length as the x_ts time series. Finally the function chart_xts() plots the chart object and returns it invisibly.

Value

A chart_Series() object returned invisibly.

Examples

1
2
3
4
5
6
7
# Plot candlestick chart with shading
rutils::chart_xts(rutils::etf_env$VTI["2015-11"],
  name="VTI in Nov 2015", ylim=c(102, 108),
  in_dic=zoo::index(rutils::etf_env$VTI["2015-11"]) > as.Date("2015-11-18"))
# Plot two time series with custom line colors
rutils::chart_xts(na.omit(cbind(rutils::etf_env$XLU[, 4],
  rutils::etf_env$XLP[, 4])), col_ors=c("blue", "green"))

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