[R-SIG-Finance] Dates not formatting properly for quarterly time series in xtsExtra
Mark Knecht
markknecht at gmail.com
Tue Jan 7 01:54:26 CET 2014
On Mon, Jan 6, 2014 at 4:25 PM, Eric Zivot <ezivot at u.washington.edu> wrote:
> I have been working on some examples of plotting time series for my new book
> Modeling Financial Time Series with R and I noticed something funny with
> plot.xts() from the R package xtsExtra when trying to plot quarterly time
> series created from the xts function to.quarterly. Here is an example:
>
>
>
>> sessionInfo()
>
> R version 3.0.2 (2013-09-25)
>
> Platform: x86_64-w64-mingw32/x64 (64-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] xtsExtra_0.0-1 quantmod_0.4-0 TTR_0.22-0 Defaults_1.1-1
>
> [5] xts_0.9-7 zoo_1.7-10
>
>
>
> loaded via a namespace (and not attached):
>
> [1] grid_3.0.2 lattice_0.20-23 tools_3.0.2
>
>
>
>> getSymbols("GS")
>
>> GS.Ad.xts = Ad(GS)
>> GS.Ad.quarterly.xts = to.quarterly(GS.Ad.xts, OHLC=FALSE)
>> periodicity(GS.Ad.quarterly.xts)
> Quarterly periodicity from 2007 Q1 to 2014 Q1
>> GS.Ad.quarterly.xts = to.quarterly(GS.Ad.xts, OHLC=FALSE)
>> periodicity(GS.Ad.quarterly.xts)
> Quarterly periodicity from 2007 Q1 to 2014 Q1
>> head(GS.Ad.quarterly.xts)
> GS.Adjusted
> 2007 Q1 191.4
> 2007 Q2 201.1
> 2007 Q3 201.5
> 2007 Q4 200.2
> 2008 Q1 154.3
> 2008 Q2 163.4
> Warning message:
> timezone of object (UTC) is different than current timezone ().
>> class(index(GS.Ad.quarterly.xts))
> [1] "yearqtr"
>> # Error in axis format for time plot
>> plot(GS.Ad.quarterly.xts, lwd=2, col="blue")
>
>
>
> In the resulting plot, the format for the axis is not correct. Instead of
> showing the date as "Q1 2007", I see "%b 2007".
>
> Also, I notice a strange error related to timezones.
>
>
>
>> Sys.timezone()
> [1] "PST"
>
>
>
> Do I have to change my system timezone to UTC prior to downloading the data
> to get rid of this error?
>
<SNIP>
Hi Eric,
I'm dealing with lots of timezone problems here that I don't
understand. However when I run your code I don't seem to see the same
problems. It would have been easier if you supplied just a code
snippet to run so please check what I culled from your message to the
list.
From Stack Overflow I see Joshua saying that for daily data there
isn't a time zone. That only matters if your data has something
smaller like hours, etc. However I also see people having trouble if
there data crosses a Daylight Savings Time change ( I think ) so I'm
very confused at the moment.
I am not finding the xtsExtra package on CRAN so I'll have to see
about R-Forge later.
In my case, with my code, below all the data is tzone == "UTC" and
I don't get the error you get. I get a plot in blue with no borders or
axis or anything. There is a warning message.
I have an example of the tzone getting messed up somewhere around
using Blotter but I'm trying to whittle it down enough to post a
question myself.
- Mark
library(quantmod)
sessionInfo()
getSymbols("GS")
GS.Ad.xts = Ad(GS)
GS.Ad.quarterly.xts = to.quarterly(GS.Ad.xts, OHLC=FALSE)
periodicity(GS.Ad.quarterly.xts)
GS.Ad.quarterly.xts = to.quarterly(GS.Ad.xts, OHLC=FALSE)
periodicity(GS.Ad.quarterly.xts)
class(index(GS.Ad.quarterly.xts))
plot(GS.Ad.quarterly.xts, lwd=2, col="blue")
Sys.timezone()
tzone(GS)
tzone(GS.Ad.xts)
tzone(GS.Ad.quarterly.xts)
> library(quantmod)
>
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=C
LC_COLLATE=C
[5] LC_MONETARY=C LC_MESSAGES=C LC_PAPER=C
LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=C
LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RMySQL_0.9-3 DBI_0.2-7
blotter_0.8.17
[4] PerformanceAnalytics_1.1.0 FinancialInstrument_1.1.9
quantmod_0.4-1
[7] TTR_0.22-0 Defaults_1.1-1 xts_0.9-7
[10] zoo_1.7-10
loaded via a namespace (and not attached):
[1] grid_3.0.2 lattice_0.20-23 tools_3.0.2
>
> getSymbols("GS")
[1] "GS"
>
> GS.Ad.xts = Ad(GS)
> GS.Ad.quarterly.xts = to.quarterly(GS.Ad.xts, OHLC=FALSE)
> periodicity(GS.Ad.quarterly.xts)
Quarterly periodicity from 2007 Q1 to 2014 Q1
>
> GS.Ad.quarterly.xts = to.quarterly(GS.Ad.xts, OHLC=FALSE)
> periodicity(GS.Ad.quarterly.xts)
Quarterly periodicity from 2007 Q1 to 2014 Q1
> class(index(GS.Ad.quarterly.xts))
[1] "yearqtr"
> plot(GS.Ad.quarterly.xts, lwd=2, col="blue")
Error in axis(1, at = xycoords$x, labels = FALSE, col = "#BBBBBB", ...) :
formal argument "col" matched by multiple actual arguments
> Sys.timezone()
[1] ""
> tzone(GS)
[1] "UTC"
> tzone(GS.Ad.xts)
[1] "UTC"
> tzone(GS.Ad.quarterly.xts)
[1] "UTC"
More information about the R-SIG-Finance
mailing list