如何按指定的蜡烛数拆分 xts OHLC 数据

问题描述 投票:0回答:1

我有蜡烛数据

len <- 10000
times <- seq(as.POSIXct("2016-01-01 00:00:00"), length = len, by = "sec")
prices <- cumsum(rnorm(len))+1000

library(xts)
xp <- xts(x = prices,order.by = times)
xp <- to.minutes5(xp)

xp

xp.Open   xp.High   xp.Low xp.Close
2016-01-01 00:04:59 1001.8097 1004.7440 986.8783 986.8783
2016-01-01 00:09:59  986.7830  995.0656 960.4920 966.7475
2016-01-01 00:14:59  965.9071  979.9402 965.2857 975.6030
2016-01-01 00:19:59  973.5659  988.7293 965.7774 983.4846
2016-01-01 00:24:59  982.7731  982.7731 945.9951 946.5125
2016-01-01 00:29:59  946.3951  949.1420 925.5131 936.8539
2016-01-01 00:34:59  935.7039  954.8570 935.7039 948.0653
2016-01-01 00:39:59  949.0397  951.8483 928.8650 942.4658
2016-01-01 00:44:59  943.3805  963.3857 939.1387 947.9653

..

chart_Series(xp)

我可以在选定的时间使用

to.period()
功能更改图表周期。

但是我怎样才能根据我设置的蜡烛数来改变图表周期呢? 比如我想把这个段变成五支蜡烛

像这样

n <- 5  # set n candles

breaks <- seq(1, nrow(xp), length.out = n+1)
abline(v=breaks,col=4,lty=2,lwd=2)

r xts
1个回答
0
投票

使用

to.minutes
所需的分钟数,其中
xp
与问题中的一样。

to.minutes(xp, 25)
© www.soinside.com 2019 - 2024. All rights reserved.