M. M. Palhoto N. Rodrigues
2003-Dec-06 17:48 UTC
[R] Axe time of series in format yy-mm-dd
I'm trying to plot a ibm stock time series. I made the download of that series, ibm <- get.hist.quote(instrument = "ibm", start = "2003-01-01",quote=c("CL")) And ibm is a serie wiht this characteristic: Start = 37623 End = 37960 Frequency = 1 When I try to plot it, ts.plot(ibm) In the graphic the axe time is represented by 37623 ... 37960, How can I put the time in the format, yy-mm-dd ? Thanks a lot [[alternative HTML version deleted]]
get.hist.quote produces times relative to Dec 31, 1899, so try this: require(tseries) require(chron) ibm <- get.hist.quote( "ibm", start = "2003-01-01", quote = "Close" ) time.ibm <- chron( time(ibm), out.format="y-m-d", origin = c( month = 12, day = 31, year = 1899 ) ) plot( time.ibm, ibm, type="l", simplify = F ) The simplify=F flag on plot forces the year to appear. Without it, only the month and day are displayed. --- Date: Sat, 6 Dec 2003 17:48:06 -0000 From: M. M. Palhoto N. Rodrigues <mendigo at netcabo.pt> To: R Help <r-help at stat.math.ethz.ch> Subject: [R] Axe time of series in format yy-mm-dd I'm trying to plot a ibm stock time series. I made the download of that series, ibm <- get.hist.quote(instrument = "ibm", start = "2003-01-01",quote=c("CL")) And ibm is a serie wiht this characteristic: Start = 37623 End = 37960 Frequency = 1 When I try to plot it, ts.plot(ibm) In the graphic the axe time is represented by 37623 ... 37960, How can I put the time in the format, yy-mm-dd ? Thanks a lot
On Sat, Dec 06, 2003 at 05:48:06PM -0000, M. M. Palhoto N. Rodrigues wrote:> I'm trying to plot a ibm stock time series. > I made the download of that series, > ibm <- get.hist.quote(instrument = "ibm", start = "2003-01-01",quote=c("CL")) > And ibm is a serie wiht this characteristic: > Start = 37623 > End = 37960 > Frequency = 1 > When I try to plot it, > ts.plot(ibm) > In the graphic the axe time is represented by 37623 ... 37960, How can I put the time in the format, > yy-mm-dd ?As you certainly read the content of 'help(get.hist.quote)', you will know that the date is stored in Julian days since the 'origin' variable. So to display dates in a more human-readable format, you need to convert from Julian dates to a proper date representation and then label the axis accordingly. Now, luckily, there are examples -- as e.g. the plotOHLC() function which is also in the tseries package. So do > IBM <- get.hist.quote(instrument = "ibm", start='2003-01-01') trying URL http://chart.yahoo.com/table.csv?s=ibm&a=11&b=31&c=2002&d=11&e=04&f=2003&g=d&q=q&y=0&z=ibm&x=.csv' Content type application/octet-stream' length unknown opened URL .......... . downloaded 11Kb time series starts 2002-12-30 time series ends 2003-12-03 > plotOHLC(IBM) which works swimmingly for mye on Linux, and displays five dates spanning from '2002-12-31' to '2003-12-04'. One caveat: plotOHLC is both a) dog-slow for larger datasets and b) meaningless as you can't see the open/close ticks anyway. Hope this helps, Dirk -- Those are my principles, and if you don't like them... well, I have others. -- Groucho Marx
I just noticed an error in my posting below. The origin in get.hist.quote is relative to day=30, not day=31. --- Date: Sat, 6 Dec 2003 14:06:49 -0500 (EST) From: Gabor Grothendieck <ggrothendieck at myway.com> To: <mendigo at netcabo.pt>, <r-help at stat.math.ethz.ch> Subject: RE: [R] Axe time of series in format yy-mm-dd get.hist.quote produces times relative to Dec 31, 1899, so try this: require(tseries) require(chron) ibm <- get.hist.quote( "ibm", start = "2003-01-01", quote = "Close" ) time.ibm <- chron( time(ibm), out.format="y-m-d", origin = c( month = 12, day = 31, year = 1899 ) ) plot( time.ibm, ibm, type="l", simplify = F ) The simplify=F flag on plot forces the year to appear. Without it, only the month and day are displayed. --- Date: Sat, 6 Dec 2003 17:48:06 -0000 From: M. M. Palhoto N. Rodrigues <mendigo at netcabo.pt> To: R Help <r-help at stat.math.ethz.ch> Subject: [R] Axe time of series in format yy-mm-dd I'm trying to plot a ibm stock time series. I made the download of that series, ibm <- get.hist.quote(instrument = "ibm", start = "2003-01-01",quote=c("CL")) And ibm is a serie wiht this characteristic: Start = 37623 End = 37960 Frequency = 1 When I try to plot it, ts.plot(ibm) In the graphic the axe time is represented by 37623 ... 37960, How can I put the time in the format, yy-mm-dd ? Thanks a lot ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help