2
我已經從.csv導入刻度數據,並且似乎無法弄清楚如何轉換爲OHLC數據。我正在尋找轉換爲1或4HR OHLC酒吧。將刻度數據轉換爲OHLC 4HR條
請幫忙!
library(TFX)
library(quantmod)
library(zoo)
library(xts)
head(data)
Name Close
2014-05-01 00:00:00 "AUD/JPY" "94.874"
2014-05-01 00:00:00 "AUD/JPY" "94.876"
2014-05-01 00:00:00 "AUD/JPY" "94.876"
2014-05-01 00:00:00 "AUD/JPY" "94.877"
2014-05-01 00:00:00 "AUD/JPY" "94.877"
2014-05-01 00:00:00 "AUD/JPY" "94.877"
is.OHLC(data)
## [1] FALSE
periodicity(data)
## 0.161999940872192 seconds periodicity from 2014-05-01 00:00:00 to 2014-05-30 20:59:58
to.weekly(data)
## Error in to.period(x, "weeks", name = name, ...) : unsupported type
to.period(data,"seconds",5)
## Error in to.period(data, "seconds", 5) : unsupported type
bars <- period.apply(data,
+ endpoints(data,"secs",60),
+ function(xx){
+ ticks=coredata(data$close)
+ c(first(ticks),max(ticks), min(ticks),
+ last(ticks))
+ })
## There were 50 or more warnings (use warnings() to see the first 50)
head(bars)
Name Close
2014-05-01 00:00:57 -Inf Inf
2014-05-01 00:01:58 -Inf Inf
2014-05-01 00:02:59 -Inf Inf
2014-05-01 00:03:56 -Inf Inf
2014-05-01 00:04:54 -Inf Inf
2014-05-01 00:05:50 -Inf Inf
to.period(data,"seconds")
## Error in to.period(data, "seconds") : unsupported type
xx<-to.minutes(data[,1],5,'minutes')
## Error in to.period(x, "minutes", k = k, name = name, ...) : unsupported type
head(data)
Name Close
2014-05-01 00:00:00 "AUD/JPY" "94.874"
2014-05-01 00:00:00 "AUD/JPY" "94.876"
2014-05-01 00:00:00 "AUD/JPY" "94.876"
2014-05-01 00:00:00 "AUD/JPY" "94.877"
2014-05-01 00:00:00 "AUD/JPY" "94.877"
2014-05-01 00:00:00 "AUD/JPY" "94.877"