Skip to content
Prev 6110 / 15274 Next

PerformanceAnalytics - small problem with Return.excess

Brian,

I have a patched version of the function, I attach it at the end of this mail.

I'm having problems with the SharpeRatio function as well.
HAM1
StdDev Sharpe:  (Rf=0%, p=95%) 0.02562881

But:
HAM1
0.4339932

And
HAM1
0.02562881

Debugging the function, it seems that the call:

 result[i, ] = apply(R, 2, srm, xR = xR, Rf = Rf, p = p, FUN = FUNCT, ...)

yields only FUN(R) but the call (while in debug mode)


srm(R,xR=xR,FUN=FUNCT)

Gives the correct result... I might be doing something wrong, but I can't see what... Ideas?

//Giuseppe

-------------------------

Return.excess = function (R, Rf = 0)
{
        R = checkData(R)
        if (!is.null(dim(Rf))) {
                Rf = checkData(Rf)
                indexseries = index(cbind(R, Rf))
                columnname.Rf = colnames(Rf)
        }
        else {
                indexseries = index(R)
                columnname.Rf = Rf
                Rf = xts(rep(Rf, length(indexseries)), order.by = indexseries)
        }
        return.excess <- function(R, Rf) {
                xR = coredata(as.xts(R) - as.xts(Rf))
        }
        result = apply(R, MARGIN = 2, FUN = return.excess, Rf = Rf)

        if (!is.matrix(result)) result = matrix(result, ncol=ncol(R))
        colnames(result) = paste(colnames(R), ">", columnname.Rf)
        result = reclass(result, R)
        return(result)
}