Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8779611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:50:01+00:00 2026-06-13T19:50:01+00:00

I am trying to calculate some function on a rolling basis on some xts

  • 0

I am trying to calculate some function on a rolling basis on some xts object. There seems to be a problem with doing so in many cases with xts after I load PerformanceAnalytics package… Please see below for example. What am I doing wrong? This is quite important to me since it brakes many of the calculations I am performing (good that it is still weekend). I have rebuilt all major packages a few hours ago. Please see my sessionInfo below.
EDIT:
Looking at this PerformanceAnalytics thing, I guess more things are broken right now. For example:

table.DownsideRisk(ret)

Error: could not find function "sd.xts"

Here is my original example:

require(quantmod)

# Get SP500 Index
getSymbols("^GSPC")

# This does not work
tail(rollapply(Cl(GSPC), 20, FUN=sd, fill=NA), 5)

# Hm, something with xts maybe?
z <- zoo(1:1500, as.Date(1:1500))
tail(rollapply(z, 20, mean, fill=NA), 5)
tail(rollapply(z, 20, sd, fill=NA), 5)

z <- as.xts(z)
tail(rollapply(z, 20, mean, fill=NA), 5)
tail(rollapply(z, 20, sd, fill=NA), 5)

require(PerformanceAnalytics)
# This does not work anymore
tail(rollapply(z, 20, sd, fill=NA), 5)
# This does not work anymore
tail(rollapply(Cl(GSPC), 20, FUN=sd, fill=NA), 5)
# Well, it looks like xts or PerformanceAnalytics problem... When I load PerformanceAnalytics, problems...

> require(quantmod)
Loading required package: quantmod
Loading required package: Defaults
Loading required package: xts
Loading required package: zoo

Attaching package: ‘zoo’

The following object(s) are masked from ‘package:base’:

    as.Date, as.Date.numeric

Loading required package: TTR
> 
> # Get SP500 Index
> getSymbols("^GSPC")
[1] "GSPC"
> 
> # This does not work
> tail(rollapply(Cl(GSPC), 20, FUN=sd, fill=NA), 5)
           GSPC.Close
2012-10-25         NA
2012-10-26         NA
2012-10-31         NA
2012-11-01         NA
2012-11-02         NA
> 
> # Hm, something with xts maybe?
> z <- zoo(1:1500, as.Date(1:1500))
> tail(rollapply(z, 20, mean, fill=NA), 5)
1974-02-05 1974-02-06 1974-02-07 1974-02-08 1974-02-09 
        NA         NA         NA         NA         NA 
> tail(rollapply(z, 20, sd, fill=NA), 5)
1974-02-05 1974-02-06 1974-02-07 1974-02-08 1974-02-09 
        NA         NA         NA         NA         NA 
> 
> z <- as.xts(z)
> tail(rollapply(z, 20, mean, fill=NA), 5)
           [,1]
1974-02-05   NA
1974-02-06   NA
1974-02-07   NA
1974-02-08   NA
1974-02-09   NA
> tail(rollapply(z, 20, sd, fill=NA), 5)

1974-02-05 NA
1974-02-06 NA
1974-02-07 NA
1974-02-08 NA
1974-02-09 NA
> 
> require(PerformanceAnalytics)
Loading required package: PerformanceAnalytics

Package PerformanceAnalytics (1.0.5.1) loaded.
Econometric tools for performance and risk analysis.
(c) 2004-2012 Peter Carl, Brian G. Peterson. License: GPL
http://r-forge.r-project.org/projects/returnanalytics/


Attaching package: ‘PerformanceAnalytics’

The following object(s) are masked from ‘package:graphics’:

    legend

> # This does not work anymore
> tail(rollapply(z, 20, sd, fill=NA), 5)
Error in FUN(.subset_xts(data, (i - width + 1):i), ...) : 
  unused argument(s) (fill = NA)
> # This does not work anymore
> tail(rollapply(Cl(GSPC), 20, FUN=sd, fill=NA), 5)
Error in FUN(.subset_xts(data, (i - width + 1):i), ...) : 
  unused argument(s) (fill = NA)
> # Well, it looks like xts or PerformanceAnalytics problem... When I load PerformanceAnalytics, problems...
> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8          LC_NUMERIC=C                 
 [3] LC_TIME=en_US.UTF-8           LC_COLLATE=en_US.UTF-8       
 [5] LC_MONETARY=en_US.UTF-8       LC_MESSAGES=en_US.UTF-8      
 [7] LC_PAPER=en_US.UTF-8          LC_NAME=en_US.UTF-8          
 [9] LC_ADDRESS=en_US.UTF-8        LC_TELEPHONE=en_US.UTF-8     
[11] LC_MEASUREMENT=en_US.UTF-8    LC_IDENTIFICATION=en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] PerformanceAnalytics_1.0.5.1 quantmod_0.3-21             
[3] TTR_0.21-1                   xts_0.8-8                   
[5] zoo_1.7-9                    Defaults_1.1-1              
[7] rj_1.1.0-4                  

loaded via a namespace (and not attached):
[1] grid_2.15.2    lattice_0.20-0 tools_2.15.2  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:50:08+00:00Added an answer on June 13, 2026 at 7:50 pm

    PerformanceAnalytics registers a rollapply.xts method that apparently has some issues.

    You can use as.zoo on your objects to use rollapply.zoo instead.

    Try tail(rollapply(as.zoo(z), 20, sd, fill=NA, align='right'), 5)

    I don’t know what other problems you’ll run into regarding sd.xts (which is not a method) and mean.xts (which is now in xts) while using PerformanceAnalytics — at best, it depends on which version you’re using.


    This may make your computer explode, but try sourcing this before running your “huge pile of code”

    rollapply.xts <- function(data, width, FUN, ...) {
      xdata <- xcoredata(data)
      out <- zoo:::rollapply.zoo(data=data, width=width, FUN=FUN, ...)
      xcoredata(out) <- xdata
      out
    }
    

    R> suppressPackageStartupMessages(library(PerformanceAnalytics))
    R> tail(rollapply(Cl(GSPC), 20, FUN=sd, fill=NA), 20)
               GSPC.Close
    2012-10-04   10.80165
    2012-10-05   10.80888
    2012-10-08   10.82280
    2012-10-09   12.94614
    2012-10-10   14.96816
    2012-10-11   16.27298
    2012-10-12   17.48353
    2012-10-15   18.42794
    2012-10-16   18.44652
    2012-10-17   18.76495
    2012-10-18         NA
    2012-10-19         NA
    2012-10-22         NA
    2012-10-23         NA
    2012-10-24         NA
    2012-10-25         NA
    2012-10-26         NA
    2012-10-31         NA
    2012-11-01         NA
    2012-11-02         NA
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to generate arrays and calculate there values depending on some function. and
I'm trying to write some code to calculate a cumulative distribution function in matlab.
I'm trying to call a php function from jquery function to calculate some values
I am trying to calculate cumulative product for subsets of xts object. Here is
I am trying to conditionally calculate some values based on user inputs in a
I'm trying to use the RQuantLib package to calculate greeks for some options but
I am trying to write some code to calculate dividend yields. I need to
I'm trying to iterate through some values, and calculate a rank. I have a
In the .Net-Framework there is a known bug when trying to calculate the weeknumber
I'm trying to learn object oriented PHP by porting some of the simple exercises

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.