Does rollapply() allow an array of results from call to function?

后端 未结 1 764
野趣味
野趣味 2020-12-21 06:45
# Loading packages

require(forecast)
require(quantmod)

# Loading OHLC xts object

getSymbols(\'SPY\', from = \'1950-01-01\')

# Selecting weekly Close prices

x &l         


        
相关标签:
1条回答
  • 2020-12-21 07:43

    It looks like using by.column=FALSE will give what you request.

    tail(rollapplyr(data = as.zoo(x), width = 750, FUN = a.ari.fun, by.column=FALSE))
    
    2012-07-13 126.0730 145.8036
    2012-07-20 126.1342 145.8616
    2012-07-27 128.9303 148.6576
    2012-08-03 129.7640 149.4975
    2012-08-10 130.5752 150.2954
    2012-08-17 132.3789 152.0963
    

    If you have PerformanceAnalytics loaded rollapply.xts will be dispatched instead of rollapply.zoo. I edited to convert the object to zoo first to make sure the right rollapply is called.

    EDIT:

    Thanks to some patching from @JoshuaUlrich, this now works with rollapply.xts,so you do not have to convert to zoo. Also, rollapply.xts is now registered in the xts package instead of PerformanceAnalytics, so you will get the same results regardless of whether or not PerformanceAnalytics is loaded. You'll need the under development version of xts -- Rev. 765 or later -- which is on R-Forge.

    rollapplyr(x, 750, a.ari.fun, by.column=FALSE)
    
    0 讨论(0)
提交回复
热议问题