An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120917/3c53455c/attachment.pl>
Problems with time format and read.csv()
5 messages · Dave, Joshua Ulrich, Costas Vorlow
Use the colClasses arg to read Date and Time as character:
dat <- read.csv("tick.csv", colClasses=c(rep("character",2),rep("numeric",6)))
HTH,
--
Joshua Ulrich | about.me/joshuaulrich
FOSS Trading | www.fosstrading.com
On Mon, Sep 17, 2012 at 1:14 PM, Costas Vorlow <costas.vorlow at gmail.com> wrote:
Hello, Following a previous post, http://www.mail-archive.com/r-sig-finance at r-project.org/msg03727.html I am having trouble with the hours format as it is picked up by the read.csv() command. The following data: "Date","Time","Open","High","Low","Close","Up","Down" 04/27/2012,0930,12.24,12.24,12.24,12.24,0,300 04/27/2012,0930,12.24,12.24,12.24,12.24,0,200 are read as datain<-read.csv('tick.csv', header=TRUE)
head(dat)
Date Time Open High Low Close Up Down 1 04/27/2012 930 12.24 12.24 12.24 12.24 0 300 2 04/27/2012 930 12.24 12.24 12.24 12.24 0 200 i.e., 0930 becomes 930. How can this be translated to a "proper" time i.e, 9:30 so I can convert the data frame to an XTS object accordingly? I try to fix it by using %k below instead of %H (which also didn't work) hf<-xts(dat[,6], as.POSIXct(paste(dat[,1], dat[,2]), format = "%m/%d/%Y %k%M")) but I get NAs
head(hf)
[,1]
<NA> 12.24
<NA> 12.24
<NA> 12.25
<NA> 12.25
<NA> 12.25
<NA> 12.25
using %I in the format= above also didn't work. I gather that this is not a
timezone problem and has to do with the way the time format is
understood by R when generating a time index for the XTS object.
Thanks in advance for your time and answers,
Costas
--
[[alternative HTML version deleted]]
_______________________________________________ R-SIG-Finance at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
You will find that using fasttime will make a huge difference in load times
if you are not happy with performance.
parseTickData <- function(inputFile) {
DAT.list <- scan(file=inputFile,
sep=",",skip=1,what=list(Date="",Time="",Close=0,Volume=0),quiet=T)
index <- fastPOSIXct(paste(DAT.list$Date,DAT.list$Time),"GMT")
DAT.xts <-
xts(data.frame(Close=DAT.list$Close,Volume=DAT.list$Volume),index)
DAT.xts <- make.index.unique(DAT.xts)
return(DAT.xts)
}
Your data must be in the format:
2012-03-23,03:00:00
-----Original Message-----
From: r-sig-finance-bounces at r-project.org
[mailto:r-sig-finance-bounces at r-project.org] On Behalf Of Costas Vorlow
Sent: Monday, September 17, 2012 2:14 PM
To: r-sig-finance at r-project.org
Subject: [R-SIG-Finance] Problems with time format and read.csv()
Hello,
Following a previous post,
http://www.mail-archive.com/r-sig-finance at r-project.org/msg03727.html
I am having trouble with the hours format as it is picked up by the
read.csv() command.
The following data:
"Date","Time","Open","High","Low","Close","Up","Down"
04/27/2012,0930,12.24,12.24,12.24,12.24,0,300
04/27/2012,0930,12.24,12.24,12.24,12.24,0,200
are read as
datain<-read.csv('tick.csv', header=TRUE)
head(dat)
Date Time Open High Low Close Up Down 1 04/27/2012 930 12.24 12.24 12.24 12.24 0 300 2 04/27/2012 930 12.24 12.24 12.24 12.24 0 200 i.e., 0930 becomes 930. How can this be translated to a "proper" time i.e, 9:30 so I can convert the data frame to an XTS object accordingly? I try to fix it by using %k below instead of %H (which also didn't work) hf<-xts(dat[,6], as.POSIXct(paste(dat[,1], dat[,2]), format = "%m/%d/%Y %k%M")) but I get NAs
head(hf)
[,1] <NA> 12.24 <NA> 12.24 <NA> 12.25 <NA> 12.25 <NA> 12.25 <NA> 12.25 using %I in the format= above also didn't work. I gather that this is not a timezone problem and has to do with the way the time format is understood by R when generating a time index for the XTS object. Thanks in advance for your time and answers, Costas -- _______________________________________________ R-SIG-Finance at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
On Mon, Sep 17, 2012 at 2:15 PM, Dave <miniflowtrader at gmail.com> wrote:
You will find that using fasttime will make a huge difference in load times
if you are not happy with performance.
parseTickData <- function(inputFile) {
DAT.list <- scan(file=inputFile,
sep=",",skip=1,what=list(Date="",Time="",Close=0,Volume=0),quiet=T)
index <- fastPOSIXct(paste(DAT.list$Date,DAT.list$Time),"GMT")
DAT.xts <-
xts(data.frame(Close=DAT.list$Close,Volume=DAT.list$Volume),index)
DAT.xts <- make.index.unique(DAT.xts)
return(DAT.xts)
}
Your data must be in the format:
2012-03-23,03:00:00
It also must be in GMT, i.e. no daylight saving time. -- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com
-----Original Message----- From: r-sig-finance-bounces at r-project.org [mailto:r-sig-finance-bounces at r-project.org] On Behalf Of Costas Vorlow Sent: Monday, September 17, 2012 2:14 PM To: r-sig-finance at r-project.org Subject: [R-SIG-Finance] Problems with time format and read.csv() Hello, Following a previous post, http://www.mail-archive.com/r-sig-finance at r-project.org/msg03727.html I am having trouble with the hours format as it is picked up by the read.csv() command. The following data: "Date","Time","Open","High","Low","Close","Up","Down" 04/27/2012,0930,12.24,12.24,12.24,12.24,0,300 04/27/2012,0930,12.24,12.24,12.24,12.24,0,200 are read as datain<-read.csv('tick.csv', header=TRUE)
head(dat)
Date Time Open High Low Close Up Down 1 04/27/2012 930 12.24 12.24 12.24 12.24 0 300 2 04/27/2012 930 12.24 12.24 12.24 12.24 0 200 i.e., 0930 becomes 930. How can this be translated to a "proper" time i.e, 9:30 so I can convert the data frame to an XTS object accordingly? I try to fix it by using %k below instead of %H (which also didn't work) hf<-xts(dat[,6], as.POSIXct(paste(dat[,1], dat[,2]), format = "%m/%d/%Y %k%M")) but I get NAs
head(hf)
[,1]
<NA> 12.24
<NA> 12.24
<NA> 12.25
<NA> 12.25
<NA> 12.25
<NA> 12.25
using %I in the format= above also didn't work. I gather that this is not a
timezone problem and has to do with the way the time format is understood by
R when generating a time index for the XTS object.
Thanks in advance for your time and answers, Costas
--
[[alternative HTML version deleted]]
_______________________________________________ R-SIG-Finance at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. _______________________________________________ R-SIG-Finance at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120917/a0493817/attachment.pl>