gpt4 book ai didi

r - 使用 R 将价格变动数据转换为 OHLC 柱

转载 作者:行者123 更新时间:2023-12-02 21:54:43 25 4
gpt4 key购买 nike

如何使用 R 将刻度数据转换为 OHLC 数据?我在这里看到了几个例子,但我遇到的问题是将实际时间转换为各个时间戳。例如,第一个时间戳是 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")

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

to.period(xx,"seconds",5)

最佳答案

创建 xts 对象后,只需使用 to.period (或包装器之一)。要将 time 正确转换为 POSIXct,您必须指定正确的格式(包括“T”)。

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

另请注意,您应该指定记录 time 列的时区。我将其指定为 "UTC",因为我不知道要使用哪个时区.

关于r - 使用 R 将价格变动数据转换为 OHLC 柱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17952082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com