[R-SIG-Finance] problem with chart.TimeSeries()

Brian G. Peterson brian at braverock.com
Fri Sep 23 12:09:38 CEST 2011


On Thu, 2011-09-22 at 09:38 -0700, Eric Zivot wrote:
> I think there is a problem with the yearmon class in zoo when running
> R 2.13 and higher. For a class project, I wanted students to make a
> "growth of a $1" plot. Here is some sample code that didn't work in R
> 2.13.1 (works in R 2.12.2, however) 

This works for me in R 2.13.1:

######

require(PerformanceAnalytics)
require(quantmod)

getSymbols('vfinx',from="2006-05-01",to="2011-05-30")

head(VFINX)

ReturnsSimple.z = Return.calculate( 
    prices= VFINX$VFINX.Adjusted ,
    method='simple'
)

chart.CumReturns(
    ReturnsSimple.z,
    wealth.index=TRUE,
    legend.loc='topleft',
    lwd=2,main='Growth of $1'
)

#######

Make sure you have the latest version of zoo/xts, there was some
ugliness lately in as.Date between zoo/xts and R-base.

Also, you'll note that my example uses the newer getSymbols rather than
get.hist.quote, and returns an xts object directly, avoiding one
conversion step, so skipping your time()->Date() index conversion
entirely.

Regards,

  - Brian

-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-SIG-Finance mailing list