[R-SIG-Finance] plot.xts

R. Michael Weylandt michael.weylandt at gmail.com
Tue Aug 14 09:16:35 CEST 2012


Readers of R-SIG-Finance,

As the community which makes the most heavy use of xts, I would like
to draw your attention to a new set of plotting functions for xts
objects available as part of Google Summer of Code 2012. This work
represents a major overhaul of previously existing plot.xts and should
provide you with the most comprehensive and flexible time series
plotting available in R. Features include:

 -- "automagic" layout construction and axis alignment
 -- smart argument recycling
 -- panel function abilities
 -- more attractive candle and bar plots for OHLC objects
 -- scatterplots to view the co-evolution of multiple series
 -- event markers
 -- regime highlighting
 -- time-oriented barplots via barplot.xts [based on code by Peter Carl]
 -- interoperability with all known R time series classes using the
xts try/reclass paradigm

while retaining the same smart axis formatting and gridlines that
plot.xts provided. We have made every effort to maintain complete
compatibility with documented usages of the old plot.xts and to be 95%
compatible with plot.zoo. My goal has been to craft a design which
uses smart defaults to put attractive and informative graphics ever at
your fingertips, while remaining flexible enough for "power-users" to
craft every detail as they desire.

Now that this work is approaching production-quality, I would like to
promote it to the community and to request your impressions, feedback,
and, most importantly, bug reports. These can be returned to me
off-list, but I welcome any examples of "power charting" from those
who may wish to show off their work in public.

In that vein, I include code for a rather nifty graphic derived from
code of Peter Carl and Timely Portfolio's klr, both of whom have
provided invaluable feedback in development.

##### Expected Shortfall of EDHEC Data #######

# install.packages("xtsExtra", source = "http://r-forge.r-project.org")

require("xtsExtra")
require("PerformanceAnalytics")
data(edhec)

p=0.95
FUN="ES"
method="gaussian"

my.panel <- function(x, y, lwd, ..., pf = parent.frame()) {
   # Reference axis
   abline(h = 0, col = "grey", lty = 2, lwd = 2)

   #get VaR for overlay similar to chart.BarVaR
   risk = apply.rolling(na.omit(y), width = 36, FUN = FUN, p = p,
method = method) #hVaR = quantile(x,probs=.01)
   lines(x = .index(risk),y = coredata(risk), type="l", col="gray60")

   #print bar style chart of returns
   plus.minus.colors <- ifelse(y < 0, ifelse(coredata(y) <
coredata(risk), "red", "gray") ,"green4")
   lines(x, y, type="h", col=plus.minus.colors, lwd = lwd)
}

plot(edhec[,c(13, 2:8)], panel = my.panel,
         layout = matrix(c(1, 1, 1, 1, 1, 1:8, 8), byrow = TRUE, ncol = 2),
         yax.loc = "flip", lwd = c(3, rep(1,6), 2), main = "ES Chart",
           blocks = list(start.time = c("2001-03-01", "2007-12-01"),
                         end.time = c("2001-11-01", "2009-06-01"),
                         col = "lightblue1"), cex.lab = 0.8)

#######################################


Currently, the code is available in a testing package known as
xtsExtra containing both plot.xts and barplot.xts. The code is
currently available in source form from r-forge and should be
available in binary form shortly via the usual incantations. I do
stress once again that this is not quite yet "frozen" code and minor
changes may occur over the next week in response to bug reports and
feature requests. We are, as always, particularly sensitive to any
unforseen regressions.

Happy charting and, perhaps more importantly, happy trading,

Michael Weylandt
http://r-forge.r-project.org/projects/xts/



More information about the R-SIG-Finance mailing list