简体   繁体   English

使用R将刻度数据转换为OHLC条

[英]Converting tick data to OHLC bars using R

How can I convert tick data into OHLC data using R? 如何使用R将刻度数据转换为OHLC数据? I have seen a couple of examples on here but the issue I am having is converting the actual times for the individual time stamps. 我在这里看到了几个示例,但是我遇到的问题是转换各个时间戳的实际时间。 For example the very first time stamp is 2013-07-29 15:30:00 . 例如,第一个时间戳是2013-07-29 15:30:00

x <- read.delim(header=TRUE, stringsAsFactor=FALSE," http://hopey.netfonds.no/tradedump.php?date=20130729&paper=AAPL.O&csv_format=txt ") x <-read.delim(header = TRUE,stringsAsFactor = FALSE,“ http://hopey.netfonds.no/tradedump.php?date=20130729&paper=AAPL.O&csv_format=txt ”)

xx <- xts(x[,c(2:3)], as.POSIXct(x[,1], "UTC", "%Y%m%dT%H%M%S")) xx <-xts(x [,c(2:3)],as.POSIXct(x [,1],“ UTC”,“%Y%m%dT%H%M%S”))

to.period(xx,"seconds",5) to.period(XX, “秒”,5)

Just use to.period (or one of the wrappers) once you've created an xts object. 创建xts对象后,只需使用to.period (或其中一个包装器)即可。 To properly convert time to POSIXct, you have to specify the correct format (including the "T"). 要将time正确转换为POSIXct,必须指定正确的格式(包括“ T”)。

xx <- xts(x[,-1], as.POSIXct(x[,1], "UTC", "%Y%m%dT%H%M%S"))
to.period(xx, "seconds")

Also note that you should specify the timezone the time column was recorded in. I specified it as "UTC" , since I don't know what timezone to use. 还要注意,您应该指定记录time列的时区。我将其指定为"UTC" ,因为我不知道要使用哪个时区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM