---------- Forwarded message ---------- From: Dean Marks <dean at aeonim.co.za> Date: 2 September 2011 13:23 Subject: Re: [R-SIG-Finance] PerformanceAnalytics apply.rolling with NAs To: "Brian G. Peterson" <brian at braverock.com> Brian, thanks for the prompt response. If you append to my minimal example: x class(x) You get something that looks like, and says it is a time series object. Am I mistaken here? In any event, I'm willing to take your advise. However, are you sure this is not a bug? Many thanks,
On 2 September 2011 13:15, Brian G. Peterson <brian at braverock.com> wrote:
On Fri, 2011-09-02 at 13:00 +0200, Dean Marks wrote:
I'm having the following issue: require( PerformanceAnalytics ) data( managers ) #This works fine: x <- managers[ , "SP500 TR"] apply.rolling( x , width = 6 ) #This produces an error (presumably due to indexes being empty) x[] <- NA apply.rolling( x , width = 6 ) ### ?Error in xts(, order.by = time(R)) : ### ?order.by requires an appropriate time-based object Is this the expected behavior? How would I avoid the error without having to check for the special case(s)?
Well, the xts error says it all in this case. ?You don't have a time series to roll *on*. ?This is a time series function, so without a time series, it simply won't work. There is the newer function rollapply.xts, but I don't recall offhand whether it has been exported yet, or rollapply (in zoo) which is less fussy about the 'time series' part, though it does of course assume the ordered observations from which zoo takes its name. I suspect your actual use case is more complicated than the minimal example you've supplied. ?In this case, whether the function you choose to apply is NA-safe is up to that function. ?Many functions in R can handle NA's, many others fail in ugly ways. ?Since we don't know what you're trying to apply over a rolling period, you will need to understand the NA behavior of the function you wish to call if your data contains NA's or other anomalies. Regards, ?- Brian -- Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock
-- Dean Marks Investment Analyst Aeon Investment Management Tel: +27 (0)21 670 5295 Fax: +27 (0)86 508 0685 Mobile: +27 (0)72 417 4720 Email: dean at aeonim.co.za www.aeonim.co.za 4th Floor, MontClare Place Cnr Campground & Main Roads Claremont, 7708 PO Box 24020, Claremont, 7735 An authorised financial services provider FSP No. 27126
Dean Marks Investment Analyst Aeon Investment Management Tel: +27 (0)21 670 5295 Fax: +27 (0)86 508 0685 Mobile: +27 (0)72 417 4720 Email: dean at aeonim.co.za www.aeonim.co.za 4th Floor, MontClare Place Cnr Campground & Main Roads Claremont, 7708 PO Box 24020, Claremont, 7735 An authorised financial services provider FSP No. 27126