plot.xts for Performance and Risk
ChuuHsiang Hung - National Chiao Tung University, Institute of Business and management - Taiwan
Joshua M. Ulrich - DV Trading, US
The goal of this document is to be a reference for people who want to understand the changes made to
quantmod and PerformanceAnalytics
fork (not commits page). Base R charting functions used in both packages were replaced by
xts::plot.xts in Josh's
xts package, developed version 0.10-0, to improve financial data visualization and make future
maintenance easier. The charting functionality in
quantstrat packages are based on
PerformanceAnalytics are backwards compatible with interfaces of other functions in
the respective package and no error or warning found in tests by
R CMD Check.
We retain the charting functionality in
quantmod but replace the inner base R charting functions by
Thus the charts created by users should be looked like the same as in the old version.
chartSeries is refactored to be a wrapper
chart_Series which is now a wrapper for
xts::plot.xts as well. So S4 method used by
chartSeries and its relevant
functions are deprecate and S4 objects
chobTA are removed. Instead,
lchob object of replot_xts class will
be returned. Except for refactoring, a
chartTheme demonstration for managing chart colors is added. Here we provide a quick
# Install developed version library(devtools) install_github('naturalsmen/quantmod', ref = 'design') install_github('joshuaulrich/xts') library(quantmod) # see demo for chartSeries and chartTheme demo(chartSeries) demo(chartTheme) # Load example data from TTR data(ttrc, package="TTR") # ttrc is from 1985 to 2006 # we only use 5 years here for demonstration x <- xts(ttrc[,-1], ttrc[,1])["1997:2001"] # create an object of replot_xts class cs <- chartSeries(x, TA=c("addVo();addSMA();addMACD();addRSI()"), TAsep=";") # create candlesticks chart cs zoomChart("2002") zoomChart("") zooom() # choose desired periods interactively dropTA("RSI") # remove RSI
Please see vignette quantmod-charts for more information.
Link to commits
log.scaleis not supported in
xts::plot.xts, special handling should be used to implement it.
unsetTAstill use S4 method and they may be refactored or deprecated in the future.
- chartTA functions outside of the addTA functions are not removed, should they?
- y-axis value only changes in the frames of even numbers when
- We implement the subset functionality by replacing plot_object$Env$xsubset directly but an error occurrs in
xts:::chart.linesfunction. Now a new
chart.linesis used in
zoom_Chart. See joshuaulrich/xts#146 for more information.
Since all the time series charting functions in PerformanceAnalytics are based on
chart.TimeSeries, changes we made to the orther
charting functions aim to make them backwards compatible with
quantstrat and coordinate with the refactored
chart.TimeSeries. Main changes here are making functions such as
charts.BarVaR to be layout-free.
Panel functionality of
xts::plot.xts is used to create multiple series charts. In addition, those functions are extended to use
invisible so that a well-documented data object with well-formatted calculated results could be passed to other graphics packages
or frameworks (e.g., dygraphs, ggviz, etc.), including interactive frameworks. Users can also access the plot object by
library(devtools) install_github('naturalsmen/PerformanceAnalytics', ref = 'fix_time_series_chart_bug') library(PerformanceAnalytics) # use example data in PerformanceAnalytics data(managers) chart.TimeSeries(managers[,1]) # return value at risk values and create charts VaR.list <- charts.BarVaR(managers[,1:3], methods = c("ModifiedVaR", "GaussianVaR", "StdDev")) VaR.list # show cumulative return, multiple-day return and drawdown value and charts performance <- charts.PerformanceSummary(managers[,1)) performance # users can access plot object by xts:::current.xts_chob() p <- xts:::current.xts_chob() names(p) p
Link to commits
- Some early commits have been merged to braverock/PerformanceAnalytics. This branch includes them and new commits of fixes for the charting functions. Latest commit returns an object with well-calculated results.
- Dynamic graph feature planned to be added at the beginning has not been implemented. It should start with full discussion on which package will be used.
- Since the plot object of
replot_xtsclass needs to be returned or printed or otherwise the chart can't be viewed, we use
environmentName(parent.frame())to determine if the plot object should be printed. For example,
charts.BarVaRcreates multiple bar charts and adds different VaR values to the charts by calling
chart.BarVaRin the loop. The chart should be printed after the loop ends. There may be a better way to handle this issue.
xts_0.10-0 povides a very convenient charting engine for users to manage time series chart
through panels. It is also more flexible for users to create their own custom functions for data exploration
and should make future maintenance easier since those packages have been integrated. In
some functions are extended to use
invisible to return an object with well-formatted calculated results that
could be passed to other graphics packages or frameworks (e.g., dygraphs, ggviz, etc.), including interactive
I'd like to thank all the community members in the GSoC-xtsExtra mailing list for their help and advice when I ran into problems during the development. Especially for Josh, thank you so much for spending so much time checking up on me and direct me when I spent time working on things outside of the project. Also very appreciate your quick reply to my questions in real-time via hangouts even if you are very busy on your full-time job. Thank Brian and Ross for your instructions to the workflow of making commits and pull requests and helpful comments to my work. Finally, thank Google Summer of Code faculty for funding this program and answering our questions quickly, giving me great opportunity and experience to make contribution to my favorite language.
Jeffrey A. Ryan and Joshua M. Ulrich. xts: eXtensible Time Series. [ONLINE] Available at: http://joshuaulrich.github.io/xts/index.html.