我有以下数据:
dput(head(trade.wide,10))
structure(c(54.7, 54.5, 54.5, 54.6, 54.65, 54.6, 54.65, 54.65,
54.65, 54.7), .indexCLASS = c("POSIXct", "POSIXt"), .indexTZ = "", tclass = c("POSIXct",
"POSIXt"), tzone = "", class = c("xts", "zoo"), index = structure(c(1459482300,
1459482302, 1459482305, 1459482306, 1459482307, 1459482308, 1459482312,
1459482314, 1459482315, 1459482317), tzone = "", tclass = c("POSIXct",
"POSIXt")), .Dim = c(10L, 1L), .Dimnames = list(NULL, "PRICE"))
dput(tail(trade.wide,10))
structure(c(84.15, 84.1, 84.1, 84.05, 84.1, 84.05, 84, 84.1,
84.1, 84.2), .indexCLASS = c("POSIXct", "POSIXt"), .indexTZ = "", tclass = c("POSIXct",
"POSIXt"), tzone = "", class = c("xts", "zoo"), index = structure(c(1472637583,
1472637584, 1472637585, 1472637586, 1472637588, 1472637595, 1472637596,
1472637597, 1472637598, 1472637600), tzone = "", tclass = c("POSIXct",
"POSIXt")), .Dim = c(10L, 1L), .Dimnames = list(NULL, "PRICE"))
我试图从开始(9:15:00)开始估计 30 分钟内的高低。
df.OHLC<-to.period(trade.wide,period = "minutes", k=30, indexAt="startof")
这就是我得到的:
head(df.OHLC,10)
trade.wide.Open trade.wide.High trade.wide.Low trade.wide.Close
2016-04-01 09:15:00 54.70 54.85 54.05 54.65
2016-04-01 09:30:07 54.65 56.50 54.65 56.05
2016-04-01 10:00:02 56.15 56.15 55.75 55.85
2016-04-01 10:30:03 55.80 56.20 55.70 56.10
2016-04-01 11:00:12 56.10 56.35 55.75 55.75
2016-04-01 11:30:12 55.75 55.80 55.40 55.50
2016-04-01 12:00:20 55.50 55.70 55.45 55.60
2016-04-01 12:30:24 55.55 55.75 55.25 55.50
2016-04-01 13:00:10 55.50 56.40 55.35 55.90
2016-04-01 13:30:17 55.85 57.35 55.75 57.20
但是,它的时间戳为 09:15: 00、09:30:07、10:00:02 ……我需要的是09:15:00、09:45:00、10:15:00…… .
我也试过period.max()
功能,但它也有类似的问题。
df.OHLC1<- do.call(rbind, lapply(split(trade.wide, "days"),function(x) period.max(x,endpoints(x,on= "minutes",k=30))))
head(df.OHLC1,10)
[,1]
2016-04-01 09:29:59 54.85
2016-04-01 09:59:56 56.50
2016-04-01 10:29:53 56.15
2016-04-01 10:59:59 56.20
2016-04-01 11:29:54 56.35
2016-04-01 11:59:52 55.80
2016-04-01 12:29:59 55.70
2016-04-01 12:59:54 55.75
2016-04-01 13:29:45 56.40
2016-04-01 13:59:59 57.35
tail(df.OHLC1)
[,1]
2016-08-31 13:29:59 86.55
2016-08-31 13:59:56 86.30
2016-08-31 14:29:59 85.85
2016-08-31 14:59:59 85.15
2016-08-31 15:29:58 84.90
2016-08-31 15:30:00 84.20
我想知道为什么这些功能不成比例地划分时间?请帮我解决这个问题。谢谢