[R-SIG-Finance] Convertion of a zoo object to a ts object

Sylvain BARTHELEMY barth at tac-financial.com
Thu May 24 10:44:36 CEST 2007


Dear All,

I use get.hist.quote to read historical prices on various quotes from
Finance Yahoo. It works fine on daily prices and most of the time on monthly
prices but it is sometimes difficult to synchronize monthly data without
duplicating months when extracting more than one quote. 

Here is an example where many months are duplicated (see at the end of the
time series that 2006-05 is duplicated because CAC40 is quoted on 2006-05-02
and AXA on 2006-05-01):
x <- get.hist.quote("^FCHI", compression = "m", start = as.Date(0), quote =
"Close")
x <- cbind( xx, get.hist.quote("CS.PA", compression = "m", start =
as.Date(0), quote = "Close") )

For the moment, to avoid these problems, I use something like:
readFromYahooM <- function(nam,quote) {
 xx.0 <- get.hist.quote(nam, compression = "m", start = as.Date(0), quote =
quote)
 xx <- ts( coredata(xx.0), frequency = 12, start =
as.numeric(as.yearmon(as.Date(start(xx.0)[1]))) )
 xx
}
x <- readFromYahooM("^FCHI","Close")
x <- cbind(x, readFromYahooM("CS.PA","Close"))
colnames(x) <- c("FCHI","CS.PA")

It works, but there is a strong assumption that all the months are present
in the two time series and the fact is that xx is a zoo object and zoo
objects can contain irregular time series ! I am sure that there should be a
more elegant way to do a conversion from a zoo object to a ts object or to
replace the "start" parameter by the exact vector of zoo dates and or
yearmon but I don't find any way do to that.

I anyone can help me, I would appreciate.
Thanks in advance.

---
Sylvain Barthélémy
Head of Quantitative Research, TAC
www.tac-financial.com | www.sylbarth.com




15:59



More information about the R-SIG-Finance mailing list