Hi, I realized that when I have irregular series to feed into lineChart, the interval of each point in the chart does not seem to take care of irregular time interval I specified in my input xts time series. But rather, lineChart seems to take each point as equal spaced time series. For example, I have the following code: library(quantmod) options(digits.sec=3) t0 <- as.POSIXct("2010-04-20 09:30:00.000"); tvec1 <- runif(1000,0,1000); tvec1 <- sort(tvec1); tvec1 <- t0+tvec1; t0 <- as.POSIXct("2010-04-20 12:30:00.000"); tvec2 <- runif(1000,0,1000); tvec2 <- sort(tvec2); tvec2 <- t0+tvec2; tvec <- c(tvec1,tvec2); data <- cumsum(rnorm(length(tvec))); tseries <- xts(data,tvec); lineChart(tseries); There are two clusters of data points around 9:30AM and 12:30PM. However, when lineChart displays result, it is quite clear that all points are set to be equally spaced in time. I'm wondering if I miss-specified any parameters or not. Any advice would be much appreciated. Thank you in advance. Robert
Brian G. Peterson
2011-Apr-29 04:17 UTC
[R] [R-SIG-Finance] Handling of irregular time series in lineChart
chartSeries and its cousins plot each period as one observation. all observations have equal time. It 'takes care of' irregular data by assuming that the rate of information is equal to the number of observations, which is a perfectly correct intuition and useful for many things. If you want instead to force a regular series, then you may do that instead. You could create bars, or use a different plotting mechanism. Often, I will create regular bars (1 minute or even 1 second is sufficient) from the raw price data, and then use some addTA overplotting to plot items of interest. Regards, - Brian -- Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock On Thu, 2011-04-28 at 20:02 -0400, Robert A'gata wrote:> Hi, > > I realized that when I have irregular series to feed into lineChart, > the interval of each point in the chart does not seem to take care of > irregular time interval I specified in my input xts time series. But > rather, lineChart seems to take each point as equal spaced time > series. For example, I have the following code: > > library(quantmod) > options(digits.sec=3) > > t0 <- as.POSIXct("2010-04-20 09:30:00.000"); > tvec1 <- runif(1000,0,1000); > tvec1 <- sort(tvec1); > tvec1 <- t0+tvec1; > > t0 <- as.POSIXct("2010-04-20 12:30:00.000"); > tvec2 <- runif(1000,0,1000); > tvec2 <- sort(tvec2); > tvec2 <- t0+tvec2; > > tvec <- c(tvec1,tvec2); > data <- cumsum(rnorm(length(tvec))); > > tseries <- xts(data,tvec); > > lineChart(tseries); > > There are two clusters of data points around 9:30AM and 12:30PM. > However, when lineChart displays result, it is quite clear that all > points are set to be equally spaced in time. I'm wondering if I > miss-specified any parameters or not. Any advice would be much > appreciated. Thank you in advance. > > Robert