[R-SIG-Finance] problem with chart.TimeSeries()
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Sep 23 14:33:56 CEST 2011
On Thu, Sep 22, 2011 at 12:38 PM, Eric Zivot <ezivot at u.washington.edu> 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)
>
>
>
>> options(digits=4, width=70)
>
>> # load packages
>
>> library("PerformanceAnalytics")
>
>> library("tseries")
>
>> start.date = "2006-05-01"
>
>> end.date = "2011-05-30"
>
>> vfinx.prices = get.hist.quote(instrument="vfinx", start=start.date,
>
> + end=end.date, quote="AdjClose",
>
> + provider="yahoo", origin="1970-01-01",
>
> + compression="m", retclass="zoo")
>
> trying URL
> 'http://chart.yahoo.com/table.csv?s=vfinx&a=4&b=01&c=2006&d=4&e=30&f=2011&g=
> m&q=q&y=0&z=vfinx&x=.csv'
>
> Content type 'text/csv' length unknown
>
> opened URL
>
> downloaded 3007 bytes
>
>
>
> time series ends 2011-05-02
>
>> # change time indices to class yearmon, which is most appropriate for
> monthly data
>
>> index(vfinx.prices) = as.yearmon(index(vfinx.prices))
>
>> ReturnsCC.z = diff(log(vfinx.prices))
>
>> ReturnsSimple.z = exp(ReturnsCC.z) - 1
>
>> chart.CumReturns(ReturnsSimple.z, wealth.index=TRUE, legend.loc="topleft",
>
> + lwd=2, main="growth of $1")
>
> Error in as.Date.default(time(y)) :
>
> do not know how to convert 'time(y)' to class "Date"
>
>> traceback()
>
> 5: stop(gettextf("do not know how to convert '%s' to class \"Date\"",
>
> deparse(substitute(x))))
>
> 4: as.Date.default(time(y))
>
> 3: as.Date(time(y))
>
> 2: chart.TimeSeries(Return.cumulative, col = colorset, legend.loc =
> legend.loc,
>
> ...)
>
> 1: chart.CumReturns(ReturnsSimple.z, wealth.index = TRUE, legend.loc =
> "topleft",
>
> lwd = 2, main = "growth of $1")
>
>
>
I am able to reproduce this bug using zoo 1.7-4. Its now fixed this
in the development version so you can either use the development
version of zoo (svn version 897 or later) or else just add this
statement to the above code for now:
source("http://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/zoo/R/yearmon.R?revision=897&root=zoo")
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-SIG-Finance
mailing list