[R-SIG-Finance] Non unique timestamp in zoo object
Gabor Grothendieck
ggrothendieck at gmail.com
Tue Sep 1 19:17:37 CEST 2009
Assuming you want the last value field and sum
of the volume fields try this:
Lines <- "1|BHARTIARTL|EQ|18:15:05|600|1
2|BHARTIARTL|EQ|18:15:05|600|99
3|GLENMARK|EQ|18:15:05|238.1|5
4|HINDALCO|EQ|18:15:05|43.75|100
5|BHARTIARTL|EQ|18:15:05|600|1
6|BHEL|EQ|18:15:05|1100|11
7|HINDALCO|EQ|18:15:06|43.2|1
8|CHAMBLFERT|EQ|18:15:06|46|10
9|CHAMBLFERT|EQ|18:15:06|46|90
10|BAJAUTOFIN|EQ|18:15:06|80|100"
library(zoo)
library(chron)
tail1 <- function(x) tail(x, 1)
cls <- c("NULL", "NULL", "NULL", "character", "numeric", "numeric")
nms <- c("", "", "", "time", "value", "volume")
z <- read.zoo(textConnection(Lines), aggregate = tail1,
FUN = times, sep = "|", colClasses = cls, col.names = nms)
# re-read using sum
z2 <- read.zoo(textConnection(Lines), aggregate = sum,
FUN = times, sep = "|", colClasses = cls, col.names = nms)
z$volume <- z2$volume
z
See zoo faq #1:
vignette("zoo-faq")
and see ?read.zoo
On Tue, Sep 1, 2009 at 12:50 PM, jatin patni<jatinpatni at gmail.com> wrote:
> I'm trying to create a zoo object from a tick data file(sample below) which
> contains timestamps only.
> Filename: "20080202.trd"
> 1|BHARTIARTL|EQ|18:15:05|600|1
> 2|BHARTIARTL|EQ|18:15:05|600|99
> 3|GLENMARK|EQ|18:15:05|238.1|5
> 4|HINDALCO|EQ|18:15:05|43.75|100
> 5|BHARTIARTL|EQ|18:15:05|600|1
> 6|BHEL|EQ|18:15:05|1100|11
> 7|HINDALCO|EQ|18:15:06|43.2|1
> 8|CHAMBLFERT|EQ|18:15:06|46|10
> 9|CHAMBLFERT|EQ|18:15:06|46|90
> 10|BAJAUTOFIN|EQ|18:15:06|80|100
>
> As you can see that timestamps are not unique even at microsecond levels.
> Inorder to create a zoo/xts object to be used with quantmod later, How do
> I:-
> 1)Do I have to merge two rows with the same timestamp, symbols, price but
> different volumes.(Do I need to do this or is there some other way possible)
> 2)Append date to the timestamp while creating the zoo/xts object
>
> I'm trying to explore the 'format' argument, and POSIX and chron but without
> much success.
>
> Thanks
>
> --
> Jatin Patni
> Tel: 91 9833 2180 52
> jatinpatni at gmail.com
> www.jatinpatni.co.nr
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>
More information about the R-SIG-Finance
mailing list