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")

 

However, if I change the time index to class Date everything works fine

 

> # re-do with time index as Date object

> index(ReturnsSimple.z) = as.Date(index(ReturnsSimple.z))

> chart.CumReturns(ReturnsSimple.z, wealth.index=TRUE, legend.loc="topleft",

+                  lwd=2, main="growth of $1")

 

 

My system info is

> library(utils)

> sessionInfo()

R version 2.13.1 (2011-07-08)

Platform: i386-pc-mingw32/i386 (32-bit)

 

locale:

[1] LC_COLLATE=English_United States.1252 

[2] LC_CTYPE=English_United States.1252   

[3] LC_MONETARY=English_United States.1252

[4] LC_NUMERIC=C                          

[5] LC_TIME=English_United States.1252    

 

attached base packages:

[1] stats     graphics  grDevices utils     datasets  methods  

[7] base     

 

other attached packages:

[1] tseries_0.10-26              quadprog_1.5-4              

[3] PerformanceAnalytics_1.0.3.2 xts_0.8-2                   

[5] zoo_1.7-2                   

 

loaded via a namespace (and not attached):

[1] grid_2.13.1     lattice_0.19-31 tools_2.13.1

 

 

 

Eric Zivot                                               

Robert Richards Chaired Professor of Economics

Adjunct Professor of Finance                            

Adjunct Professor of Statistics

Adjunct Professor of Applied Mathematics (starting Sept, 2011)

Department of Economics

Box 353330                  email:  ezivot@u.washington.edu 

University of Washington    phone:  206-543-6715            

Seattle, WA 98195-3330
www:  http://faculty.washington.edu/ezivot                  

 


	[[alternative HTML version deleted]]

