Question

Reproducible code:

#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)

In my R session the last command returns

Error in coredata.xts(x) : currently unsupported data type

This is quite strange, because is(SP500) says

> is(SP500)
[1] "xts"      "oldClass" "xtsORzoo"

which is good for period.apply(). It's likely there's something wrong with my 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
Was it helpful?

Solution

If you want the highest price for each quarter, you need to use max(Hi(foo)). Hi returns the "High" column, which is a problem because it contains more than 1 value per quarter. Try this instead:

apply.quarterly(Hi(SP500), max)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top