I am trying to use R XTS package to.minutes to create 15m and 30m time series from 5m. I have an xts object, which is date-time followed by OHLC. Info about xts object x is below:
我正试着使用R XTS包。分钟从500米创造出1500米和3000米的时间序列。我有一个xts对象,它是date-time,然后是OHLC。关于xts对象x的信息如下:
head(x) shows the following:
头(x)显示如下:
High Low Open Close Volume
2010-05-03 09:00:00 106.08 105.95 106.06 106.00 1055 2010-05-03 09:05:00 106.03 105.75 106.00 105.77 4369 2010-05-03 09:10:00 105.77 105.59 105.77 105.68 4125 2010-05-03 09:15:00 105.84 105.66 105.69 105.80 2457 2010-05-03 09:20:00 105.89 105.71 105.80 105.83 1788 2010-05-03 09:25:00 105.89 105.78 105.84 105.78 977
2010年10月10日上午10:00 106.00 106.00 106.00 106.00 106.00 106.00 106.00 106.00 106.00 106.00 106.00 106.00 106.00 106.00105.7105.7105.7105.7105.7106.105.7105.7105.7106.00 105.7106.00 105.7106.00 105.7106.00 105.7106.00 105.7106.00 105.7106.00 105.7106.00 105.7106.00 105.7106.00 105.7106.00 105.7105.7105.7105.77 105.78
str(x) shows the following:
str(x)显示如下:
> str(x)
‘zoo’ series from 2010-05-03 09:00:00 to 2013-06-10 14:30:00 Data: num [1:222473, 1:5] 106 106 106 106 106 ... - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : chr [1:5] "High" "Low" "Open" "Close" ... Index: POSIXct[1:222473], format: "2010-05-03 09:00:00" "2010-05-03 09:05:00" "2010-05-03 09:10:00" ...
“动物园”系列:2010-05-03 09:00至2013-06-10 14:30:00数据:num[1:222473, 1:5] 106 106 106 106…- attr(*,“dimnames”)= 2 ..美元:零. .$:chr [1:5] "High" "Low" "Open" "Close"…索引:POSIXct[1:222473],格式:"2010-05-03 09:00 " "2010-05-03 09:05:00" "2010-05-03 09:10 "…
str(head(index(x))) shows the following:
str(头(索引(x)))显示如下:
head(str(index(x)))
POSIXct[1:222473], format: "2010-05-03 09:00:00" "2010-05-03 09:05:00" "2010-05-03 09:10:00" ... NULL
POSIXct[1:222473],格式:"2010-05-03 09:00:00" "2010-05-03 09:05:00" "2010-05-03 09:10 "…零
When I convert the time series to 15m, the series starts at 09:10:00 followed by 15 minutes increments instead of starting at 09:15:00 followed by 15 minutes increments
当我将时间序列转换为15m时,这个系列从09:10:00开始,然后是15分钟,而不是从09:15:00开始,然后是15分钟的增量。
> head(to.minutes(x, k=15))
x.Open x.High x.Low x.Close x.Volume
2010-05-03 09:10:00 106.08 105.95 105.77 105.68 9549 2010-05-03 09:25:00 105.84 105.78 105.69 105.78 5222 2010-05-03 09:40:00 105.80 105.92 105.62 106.12 9727 2010-05-03 09:55:00 106.17 106.00 106.01 106.22 6320 2010-05-03 10:10:00 106.26 106.07 106.15 106.14 8422 2010-05-03 10:25:00 106.57 106.38 106.15 106.37 10422
2010年10月10日上午10点10分105.88 105.78 105.78 105.78 105.78 105.78 105.78 105.705 105.78 105.78 105.78 105.907 106.07 106.08 106.08 106.08 106.08 106.08 106.08 105.08 105.07 105.08
The same issue when I convert the time series to 30m, the series starts at 09:25:00 followed by 30 minutes increments instead of starting at 09:30:00 followed by 30 minutes increments
同样的问题,当我将时间序列转换为30m时,这个系列从09:25:00开始,接着是30分钟,而不是从09:30:00开始,然后是30分钟的增量。
> head(to.minutes(x, k=30))
x.Open x.High x.Low x.Close x.Volume
2010-05-03 09:25:00 106.08 105.95 105.69 105.78 14771 2010-05-03 09:55:00 105.80 106.00 105.62 106.22 16047 2010-05-03 10:25:00 106.26 106.38 106.15 106.37 18844 2010-05-03 10:55:00 106.37 106.27 106.01 106.00 17193 2010-05-03 11:25:00 106.04 106.20 105.95 106.29 9075 2010-05-03 11:55:00 106.34 106.35 106.24 106.39 8517
2010年10月10日上午10点55分105.00 106.00 106.00 106.00 106.00 106.00 106.00 106.00 106.00 106.00 106.08 106.08 106.08 106.08 106.08 106.08 106.08 106.08 106.08 106.08 106.08
I also tried the same using 1 minute data and had the same issue. Any thought on what might be causing this issue and how to resolve it? Thanks
我也用1分钟的数据做了同样的尝试。有没有想过是什么导致了这个问题以及如何解决这个问题?谢谢
1 个解决方案
#1
4
This is pretty clearly described on the ?to.minutes
help page. The default is for the groups to start at the end of your data and work backwards so it doesn't necessarily pay attention to what the first value is. However, you can explicity set the indexAt=
parameter to "startof"
. For example
这很清楚地描述了。分钟帮助页面。默认情况下,组要从数据的末尾开始,向后工作,这样就不必关注第一个值是什么。但是,您可以将indexAt=参数设置为“startof”。例如
x <- zoo(runif(25), order.by=seq(as.POSIXct("2010-05-03 09:00:00"),
as.POSIXct("2010-05-03 11:00:00"), by="5 min"))
to.minutes15(x)
# x.Open x.High x.Low x.Close
# 2010-05-03 09:10:00 0.35570172 0.3557017 0.04524480 0.04524480
# 2010-05-03 09:25:00 0.78939084 0.7893908 0.44032175 0.44032175
# 2010-05-03 09:40:00 0.05272398 0.5381755 0.05272398 0.53817548
# 2010-05-03 09:55:00 0.02198503 0.1113298 0.02198503 0.11132980
# 2010-05-03 10:10:00 0.78785210 0.8804505 0.04152860 0.04152860
# 2010-05-03 10:25:00 0.79317091 0.9497044 0.54751546 0.94970444
# 2010-05-03 10:40:00 0.03886176 0.7425681 0.03886176 0.06614893
# 2010-05-03 10:55:00 0.58684500 0.5868450 0.02794687 0.14291696
# 2010-05-03 11:00:00 0.11713868 0.1171387 0.11713868 0.11713868
versus
与
to.minutes15(x, indexAt="startof")
# x.Open x.High x.Low x.Close
# 2010-05-03 09:00:00 0.35570172 0.3557017 0.04524480 0.04524480
# 2010-05-03 09:15:00 0.78939084 0.7893908 0.44032175 0.44032175
# 2010-05-03 09:30:00 0.05272398 0.5381755 0.05272398 0.53817548
# 2010-05-03 09:45:00 0.02198503 0.1113298 0.02198503 0.11132980
# 2010-05-03 10:00:00 0.78785210 0.8804505 0.04152860 0.04152860
# 2010-05-03 10:15:00 0.79317091 0.9497044 0.54751546 0.94970444
# 2010-05-03 10:30:00 0.03886176 0.7425681 0.03886176 0.06614893
# 2010-05-03 10:45:00 0.58684500 0.5868450 0.02794687 0.14291696
# 2010-05-03 11:00:00 0.11713868 0.1171387 0.11713868 0.11713868
#1
4
This is pretty clearly described on the ?to.minutes
help page. The default is for the groups to start at the end of your data and work backwards so it doesn't necessarily pay attention to what the first value is. However, you can explicity set the indexAt=
parameter to "startof"
. For example
这很清楚地描述了。分钟帮助页面。默认情况下,组要从数据的末尾开始,向后工作,这样就不必关注第一个值是什么。但是,您可以将indexAt=参数设置为“startof”。例如
x <- zoo(runif(25), order.by=seq(as.POSIXct("2010-05-03 09:00:00"),
as.POSIXct("2010-05-03 11:00:00"), by="5 min"))
to.minutes15(x)
# x.Open x.High x.Low x.Close
# 2010-05-03 09:10:00 0.35570172 0.3557017 0.04524480 0.04524480
# 2010-05-03 09:25:00 0.78939084 0.7893908 0.44032175 0.44032175
# 2010-05-03 09:40:00 0.05272398 0.5381755 0.05272398 0.53817548
# 2010-05-03 09:55:00 0.02198503 0.1113298 0.02198503 0.11132980
# 2010-05-03 10:10:00 0.78785210 0.8804505 0.04152860 0.04152860
# 2010-05-03 10:25:00 0.79317091 0.9497044 0.54751546 0.94970444
# 2010-05-03 10:40:00 0.03886176 0.7425681 0.03886176 0.06614893
# 2010-05-03 10:55:00 0.58684500 0.5868450 0.02794687 0.14291696
# 2010-05-03 11:00:00 0.11713868 0.1171387 0.11713868 0.11713868
versus
与
to.minutes15(x, indexAt="startof")
# x.Open x.High x.Low x.Close
# 2010-05-03 09:00:00 0.35570172 0.3557017 0.04524480 0.04524480
# 2010-05-03 09:15:00 0.78939084 0.7893908 0.44032175 0.44032175
# 2010-05-03 09:30:00 0.05272398 0.5381755 0.05272398 0.53817548
# 2010-05-03 09:45:00 0.02198503 0.1113298 0.02198503 0.11132980
# 2010-05-03 10:00:00 0.78785210 0.8804505 0.04152860 0.04152860
# 2010-05-03 10:15:00 0.79317091 0.9497044 0.54751546 0.94970444
# 2010-05-03 10:30:00 0.03886176 0.7425681 0.03886176 0.06614893
# 2010-05-03 10:45:00 0.58684500 0.5868450 0.02794687 0.14291696
# 2010-05-03 11:00:00 0.11713868 0.1171387 0.11713868 0.11713868