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

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


Since my post, I have found I way to do that and it seems to work:

xx.zoo <- get.hist.quote("^FCHI", compression = "m", start = as.Date(0),
quote = "Close")
xx.ts  <- as.ts(aggregate(xx.zoo, as.yearmon, mean))	


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

-----Message d'origine-----
De : r-sig-finance-bounces at stat.math.ethz.ch
[mailto:r-sig-finance-bounces at stat.math.ethz.ch] De la part de Sylvain
BARTHELEMY
Envoyé : jeudi 24 mai 2007 10:45
À : r-sig-finance at stat.math.ethz.ch
Objet : [R-SIG-Finance] Convertion of a zoo object to a ts object

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

_______________________________________________
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.

No virus found in this incoming message.


15:59
 




15:59



More information about the R-SIG-Finance mailing list