2012-11-02 19 views
3

我無法使用Quantmod getSymbols()調用從yahoo獲得當天的OHLCV數據。這些數據存在於雅虎,也可以在我的圖表平臺上看到今天的OHLCV數據。作爲解決方法,我從yahoo使用getQuote(..)調用得到了今天的EOD報價。但是當我試圖通過rbind把它附加到下載的符號數據時,數據對象被填充爲NULL。quantmod ...無法獲得當天的OHLCV符號數據

我很欣賞任何關於如何將今日報價附加到下載的歷史符號數據或我可以在營業時間後撥打的任何R API來獲取包括今天在內的符號EOD(OHLCV數據)的建議。謝謝。

library(quantmod) 
library(blotter) 
library(PerformanceAnalytics) 

getSymbols("SPY") 
spy.quote = getQuote("SPY", what = yahooQuote.EOD) 

> tail(SPY, n=3) 
      SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted 
2012-10-25 142.02 142.28 140.57 141.43 134457400  141.43 
2012-10-26 141.30 141.84 140.39 141.35 146023500  141.35 
2012-10-31 141.85 142.03 140.68 141.35 103341300  141.35 

> spy.quote 
      Trade Time Open High Low Close Volume 
SPY 2012-11-01 04:00:00 141.65 143.01 141.52 142.83 100990760 

> SPY = rbind(SPY, spy.quote) 
> tail(SPY, n=3) 
      SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted 
      NULL  NULL  NULL NULL  NULL  NULL    
      NULL  NULL  NULL NULL  NULL  NULL   
spy.quote NULL  NULL  NULL NULL  NULL  NULL 

回答

3

您需要的報價數據從data.frame轉換爲xts對象和調整後的價格增加一列。那你可以rbind

getSymbols("SPY", src='yahoo', to='2012-10-31') 
spy.quote = getQuote("SPY", what = yahooQuote.EOD) 

# convert to xts 
xts.quote <- xts(spy.quote[, -1], as.Date(spy.quote[, 1])) # use Date for indexClass 
xts.quote$Adjusted <- xts.quote[, 'Close'] # add an Adjusted column 

tail(rbind(SPY, xts.quote), 3) 
      SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted 
2012-10-26 141.30 141.84 140.39 141.35 146023500  141.35 
2012-10-31 141.85 142.03 140.68 141.35 103341300  141.35 
2012-11-01 141.65 143.01 141.52 142.83 100995568  142.83 
+0

謝謝。它解決了這個問題。 – Atrad