可重复的代码:
#install.packages('quantmod')
require(quantmod)
# Downloading data and merging them
getSymbols(c('^GSPC', '^GDAXI'), from = '1900-01-01')
X <- na.omit(merge(GSPC, GDAXI))
SP500 <- X[,substr(colnames(X), 1, 4) == 'GSPC']
DAX <- X[,substr(colnames(X), 1, 5) == 'GDAXI']
# Code
apply.quarterly(SP500, Hi)
在我的R
会话中,最后一个命令返回
Error in coredata.xts(x) : currently unsupported data type
这很奇怪,因为is(SP500)
说
> is(SP500)
[1] "xts" "oldClass" "xtsORzoo"
这对period.apply()
有用。我的sessionInfo()
:
R version 3.0.1 (2013-05-16)
Platform: i386-w64-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats4 stats graphics grDevices datasets utils methods base
other attached packages:
[1] quantmod_0.4-0 TTR_0.22-0 Defaults_1.1-1
[4] PerformanceAnalytics_1.1.0 xts_0.9-4 yuima_0.1.210
[7] zoo_1.7-10 rcom_3.1-2 rscproxy_2.0-5
loaded via a namespace (and not attached):
[1] grid_3.0.1 lattice_0.20-15 timeDate_3010.98 timeSeries_3010.97
[5] tools_3.0.1
答案 0 :(得分:1)
如果您想要每个季度的最高价格,则需要使用max(Hi(foo))
。 Hi
会返回“高”列,这是一个问题,因为它每季度包含的值超过1。试试这个:
apply.quarterly(Hi(SP500), max)