2014-09-19 21 views
1

我有R新手,一直跟着從YouTube的教程由Chris Reeves
我使用與to.period XTS從蜱創建OHLC /秒數據。to.period返回錯誤嘗試設置指標4/4在SET_STRING_ELT R中

我的代碼

Last = AAPL.Last 
Bid = AAPL.Bid 
Ask = AAPL.Ask 

colnames(Last) = c("TimeStamp","Price","Size") 
colnames(Bid) = c("TimeStamp","Price","Size") 
colnames(Ask) = c("TimeStamp","Price","Size") 

Last$TimeStamp = strptime(Last$TimeStamp, "%Y%m%d %H%M%S") 
Bid$TimeStamp = strptime(Bid$TimeStamp, "%Y%m%d %H%M%S") 
Ask$TimeStamp = strptime(Ask$TimeStamp, "%Y%m%d %H%M%S") 

require("xts") 
xtsLast = as.xts(Last$Price,order.by=Last$TimeStamp,frequency=NULL) 
xtsAsk = as.xts(Ask$Price,order.by=Ask$TimeStamp,frequency=NULL) 
xtsBid = as.xts(Bid$Price,order.by=Bid$TimeStamp,frequency=NULL) 

require("quantmod") 
chartSeries(xtsLast) 

bars = to.period(xtsLast, 
       period = "seconds", 
       k=60, 
       indexAt = "startof", 
       name = NULL, 
       OHLC = TRUE): 
require("quantmod") 
chartSeries(bars) 

返回的錯誤是:

錯誤to.period(xtsLast,週期= 「秒」,K = 60,indexAt = 「STARTOF」 ,:嘗試在SET_STRING_ELT中設置索引4/4

我用Google搜索了一個答案,但我無法獲得完整答案,因此請在此處詢問。這是一個非常基本的問題。

我正在使用Rx64使用RStudio的Windows 7 3.1.1。

感謝, ^ h

+0

您尚未提供足夠的信息給[reproduce](http://stackoverflow.com/q/5963269/271616)該錯誤,這使得很難幫助您。 – 2014-09-19 11:56:26

回答

0

這工作,如果你不設置name = NULL

require(quantmod) 
base_url <- "http://www.reevesresearch.com/codes/TickDataAAPL/" 
Last <- read.table(paste0(base_url, "AAPL.Last.txt"), sep=";") 
colnames(Last) <- c("TimeStamp","Price","Size") 
Last$TimeStamp <- strptime(Last$TimeStamp, "%Y%m%d %H%M%S") 
xtsLast <- xts(Last$Price, order.by=Last$TimeStamp) 
bars <- to.minutes(xtsLast, k=1, indexAt="startof") 
+0

現在在R-forge上固定爲r859,因此指定'name = NULL'將起作用。 – 2014-09-22 14:44:24

+0

謝謝Joshua - 我會記住將來會增加更多細節。 你的建議已經做到了,但是我使用to.periods而不是.minutes。 to.periods有問題嗎? – AlgoTraderNew 2014-09-23 18:49:15

+0

@AlgoTraderNew:'to.minutes'只是'to.period'周圍的一個包裝,所以'to.period'沒什麼問題。 – 2014-09-23 18:53:30

相關問題