Skip to content
Prev 1397 / 15274 Next

Convertion of a zoo object to a ts object

Exactly what I needed !
Thanks.

---
Sylvain Barth?l?my
Head of Quantitative Research, TAC
www.tac-financial.com | www.sylbarth.com
 
-----Message d'origine-----
De : Achim Zeileis [mailto:Achim.Zeileis at wu-wien.ac.at] 
Envoy? : jeudi 24 mai 2007 11:28
? : Sylvain BARTHELEMY
Cc : r-sig-finance at stat.math.ethz.ch
Objet : Re: [R-SIG-Finance] Convertion of a zoo object to a ts object

Sylvain:
OK, there are some useful tools in this situation. Which you want to use
depends what exactly what to end up with.

## obtain series
x <- get.hist.quote("^FCHI", compression = "m", start = as.Date(0),
   quote = "Close")
y <- get.hist.quote("CS.PA", compression = "m", start = as.Date(0),
   quote = "Close")

## merge based on "Date" time stamps (which might not match) xy <- merge(x,
y)

## remove NAs by averaging in each month
xy1 <- aggregate(xy, as.yearmon, mean, na.rm = TRUE) ## (which gives NaN
rather NA for the first "y" observations)

## alternatively: first go to "yearmon" scale and then merge
x2 <- aggregate(x, as.yearmon, mean)
y2 <- aggregate(y, as.yearmon, mean)
xy2 <- merge(x2, y2)

## to convert to "ts", you can simply do xy1ts <- as.ts(xy1) xy2ts <-
as.ts(xy2)

## Of course, you could also keep the merged series with "Date" time ##
stamp, e.g., using the first of the month xy2d <- xy2
time(xy2d) <- as.Date(time(xy2))

hth,
Z

No virus found in this incoming message.


15:59
 




15:59