[R] zoo.read intraday data

szimine szimine at gmail.com
Wed Dec 22 05:36:51 CET 2010


Hi Gabor et al.

the 
 f3 <- function(...) as.POSIXct(paste(...), format = "%Y%m%d %H:%M:%S" ) 

helped me to read intraday data from file
######
<TICKER>,<NAME>,<PER>,<DATE>,<TIME>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>,<OPENINT>
ICE.BRN,ice.brn_m5,5,20100802,10:40:00,79.21000,79.26000,79.16000,79.20000,238,0
ICE.BRN,ice.brn_m5,5,20100802,10:45:00,79.19000,79.26000,79.19000,79.21000,413,0
######

##intraday data 5m  file
fnameId= "./finam_brn_m5.csv"
pDateTimeColumns <- list(4,5) 
b <- read.zoo(fnameId, index=pDateTimeColumns , sep=",", header=TRUE, 
FUN=f3   )
xb <- as.xts(b)


> head(b,2) ##
                    X.TICKER. X.NAME.    X.PER. X.OPEN. X.HIGH. X.LOW.
X.CLOSE. X.VOL. X.OPENINT.
2010-08-02 10:40:00 ICE.BRN   ice.brn_m5 5      79.21   79.26   79.16  79.20    
238   0         
2010-08-02 10:45:00 ICE.BRN   ice.brn_m5 5      79.19   79.26   79.19  79.21    
413   0

problem is that after the conversion to xts  numeric values got converted to
chars

> head(xb,2)
                    X.TICKER. X.NAME.      X.PER. X.OPEN. X.HIGH. X.LOW. 
X.CLOSE. X.VOL. X.OPENINT.
2010-08-02 10:40:00 "ICE.BRN" "ice.brn_m5" "5"    "79.21" "79.26" "79.16"
"79.20"  " 238" "0"       
2010-08-02 10:45:00 "ICE.BRN" "ice.brn_m5" "5"    "79.19" "79.26" "79.19"
"79.21"  " 413" "0" 


and quantmod charting does  not work.

Q.  how to prevent converting to char with xts ? 

I suspect the problem is that index is constructed from two columns  date 
and time. 


> sessionInfo()
R version 2.12.1 (2010-12-16)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
locale:
[1] C
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
other attached packages:
[1] quantmod_0.3-15 TTR_0.20-2      Defaults_1.1-1  xts_0.7-6.11   
zoo_1.7-0     


Slava

-- 
View this message in context: http://r.789695.n4.nabble.com/zoo-read-intraday-data-tp3010256p3160102.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list