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

