Bernd,

In short, you need `FUN=tt` instead of `tt` in your call to
PerformanceAnalytics:::apply.rolling.

> args(apply.rolling)
function (R, width, trim = TRUE, gap = 12, by = 1, FUN = "mean", ...)

Your call is handing `tt` to the `trim` argument.

> summary(apply.rolling(bp.ret.zoo, 100, FUN=tt))
     Index            apply.rolling(bp.ret.zoo, 100, FUN = tt)
 Min.   :2008-01-02   Min.   : 0.02251
 1st Qu.:2008-12-10   1st Qu.: 0.27019
 Median :2009-11-24   Median : 0.53615
 Mean   :2009-11-25   Mean   : 0.53226
 3rd Qu.:2010-11-08   3rd Qu.: 0.77445
 Max.   :2011-10-24   Max.   : 0.99875
                      NA's   :99.00000

HTH,
Garrett




On Tue, Oct 25, 2011 at 5:24 AM, Bernd Dittmann <bd10stats@googlemail.com>wrote:

> # Hi all,
>
> # I have been exploring the xts object class for the last few days
> # and played around with apply.rolling(). I am getting negative
> # p-values when using t.test within apply.rolling(...)
> # but not rollapply(...). Without further ado, here's an example:
>
> require("tseries")
> require("quantmod")
> require("PerformanceAnalytics")
>
> getSymbols("BP.L")
> bp.xts <- window(Cl(BP.L), start="2008-01-01")
> bp.ret.xts <- ROC(bp.xts, type="continuous")
> bp.ret.xts <- na.omit(bp.ret.xts)
>
> bp.zoo <- get.hist.quote(instrument="BP.L", start="2008-01-01",
> quote="Close")
> bp.ret.zoo <- diff(log(bp.zoo))
>
> tt<- function(x){as.numeric(t.test(as.numeric(x))$p.value)}
>
> # apply t-test over rolling window
> # first the zoo object
> summary(rollapply(bp.ret.zoo, width=100, tt, align="right"))
>
> # now for the xts object
> summary(na.omit(apply.rolling(bp.ret.zoo, 100, tt)))
> # negative p-values are rather surprising
>
> # let's try this with converting the xts object into a matrix
> bp.xts.mat <- matrix(bp.ret.xts[,1])
> summary(rollapply(bp.xts.mat, width=100, tt, align="right"))
> # works just fine
>
> # let's convert the xts into a zoo object
> summary(na.omit(apply.rolling(zoo(bp.ret.xts), 100, tt)))
> # negative p-values again ;-(
>
> # I am sure it's trivial, but unfortunately cannot see the trees before the
> forest.
> # Any pointers most welcome.
>
> # Many thanks & best regards,
>
> # Bernd
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>

	[[alternative HTML version deleted]]

