【发布时间】:2016-08-06 20:57:18
【问题描述】:
在xts 中进行周期聚合时,如何指定哪些列构成 OHLCV?此外,它正在从我的原始数据(“窗口”)中丢失一列。
也许有一种方法可以将自己的聚合函数提供给to.period - 将感谢有用的指针。
> head(to.period(spy,period="minutes",k=5, indexAt="startof"),5)
spy.Open spy.High spy.Low spy.Close spy.Volume
2016-05-19 06:30:00 60 204.20 204.09 204.02 537530
2016-05-19 06:35:00 60 204.32 204.16 204.23 482436
2016-05-19 06:40:00 60 204.50 204.38 204.39 441800
2016-05-19 06:45:00 60 204.53 204.31 204.20 579161
2016-05-19 06:50:00 60 204.20 203.86 203.72 849998
> head(spy,10)
window open high low close volume
2016-05-19 06:30:00 60 204.030 204.09 203.900 203.91 144840
2016-05-19 06:31:00 60 203.900 204.20 203.900 204.20 94846
2016-05-19 06:32:00 60 204.200 204.23 204.110 204.19 68895
2016-05-19 06:33:00 60 204.180 204.30 204.160 204.18 110701
2016-05-19 06:34:00 60 204.160 204.16 204.020 204.10 118248
2016-05-19 06:35:00 60 204.100 204.16 204.010 204.06 78303
2016-05-19 06:36:00 60 204.060 204.20 204.040 204.19 67314
2016-05-19 06:37:00 60 204.200 204.33 204.140 204.33 147779
2016-05-19 06:38:00 60 204.320 204.33 204.130 204.27 109549
2016-05-19 06:39:00 60 204.270 204.34 204.230 204.24 79491
【问题讨论】:
-
to.period需要一个单变量或 OHLC 类型的时间序列对象。在应用此功能之前,您必须删除window列。