我想將幾個xts對象合併到一個xts對象中。這樣我就可以得到收盤價格上的對象之間的相關矩陣。將多個XTS對象合併爲一個XTS對象
下面的代碼拉低外匯數據
require(xts)
symbols <- c("AUDJPY", "AUDUSD", "CHFJPY", "EURCHF", "EURGBP", "EURJPY",
"EURUSD", "GBPCHF", "GBPJPY", "GBPUSD", "NZDUSD", "USDCAD",
"USDCHF", "USDJPY", "XAGUSD", "XAUUSD")
fxhistoricaldata <- function(Symbol, timeframe, download = FALSE, bandwidth) {
# setup temp folder
temp.folder <- tempdir()
filename <- paste(temp.folder, '/',"fxhistoricaldata_",Symbol ,"_" ,timeframe,".csv", sep='')
if(download) {
downloadfile <- paste("http://api.fxhistoricaldata.com/v1/indicators?instruments=" ,Symbol ,"&expression=open,high,low,close&item_count=10000&format=csv&timeframe=" ,timeframe,sep='')
download.file(downloadfile, filename, mode = 'wb')
}
tempdf <- read.csv(filename)
colnames(tempdf) <- c("Curr","Date","Open","High","Low","Close")
tempdf <- tempdf[c("Date","Open","High","Low","Close")]
result <- xts(tempdf[,-1], order.by=as.POSIXct(tempdf[,1]))
return(result)
}
AUDJPY <- fxhistoricaldata('AUDJPY' ,'day',download=T,5)
AUDUSD <- fxhistoricaldata('AUDUSD' ,'day',download=T,5)
CHFJPY <- fxhistoricaldata('CHFJPY' ,'day',download=T,5)
EURCHF <- fxhistoricaldata('EURCHF' ,'day',download=T,5)
EURGBP <- fxhistoricaldata('EURGBP' ,'day',download=T,5)
EURJPY <- fxhistoricaldata('EURJPY' ,'day',download=T,5)
EURUSD <- fxhistoricaldata('EURUSD' ,'day',download=T,5)
GBPCHF <- fxhistoricaldata('GBPCHF' ,'day',download=T,5)
GBPJPY <- fxhistoricaldata('GBPJPY' ,'day',download=T,5)
GBPUSD <- fxhistoricaldata('GBPUSD' ,'day',download=T,5)
NZDUSD <- fxhistoricaldata('NZDUSD' ,'day',download=T,5)
USDCAD <- fxhistoricaldata('USDCAD' ,'day',download=T,5)
USDCHF <- fxhistoricaldata('USDCHF' ,'day',download=T,5)
USDJPY <- fxhistoricaldata('USDJPY' ,'day',download=T,5)
XAGUSD <- fxhistoricaldata('XAGUSD' ,'day',download=T,5)
XAUUSD <- fxhistoricaldata('XAUUSD' ,'day',download=T,5)
我想要的結果會是這個樣子與收盤價的符號名以下,但對於所有的符號名
AUDJPY AUDUSD
2016-01-01 1.200 1.300
2016-01-02 1.21 1.31
所述XTS之一的
實施例對象
請提供[可重現的示例](http://stackoverflow.com/q/5963269/271616)。數據圖片沒有幫助。 –
更新後的代碼謝謝 –