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

View source: R/rutils.R

chart_xtsR Documentation

Plot either a line plot or a candlestick plot of an xts time series, with custom line colors, y-axis range, and with vertical background shading.

Description

A wrapper for function chart_Series() from package quantmod.

Usage

chart_xts(xtsv, colors = NULL, ylim = NULL, indic = NULL, x11 = TRUE, ...)

Arguments

xtsv

An xts time series or an OHLC time series.

colors

A vector of strings with the custom line colors.

ylim

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

indic

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

x11

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 xtsv 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 indic argument, using function add_TA(). The indic argument should have the same length as the xtsv time series. Finally the function chart_xts() plots the chart object and returns it invisibly.

Value

A chart_Series() object returned invisibly.

Examples

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

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