[R-SIG-Finance] PerformanceAnalytics - small problem with Return.excess
Giuseppe Milicia
Giuseppe.Milicia at makoglobal.com
Mon May 10 17:52:42 CEST 2010
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.
>SharpeRatio(managers[,1,drop=FALSE], FUN="StdDev")
HAM1
StdDev Sharpe: (Rf=0%, p=95%) 0.02562881
But:
> mean(managers[, 1, drop = FALSE])/sd(managers[, 1, drop = FALSE])
HAM1
0.4339932
And
> sd(managers[, 1, drop = FALSE])
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)
}
________________________________________
From: Brian G. Peterson [brian at braverock.com]
Sent: 06 May 2010 12:28
To: Giuseppe Milicia
Cc: r-sig-finance at stat.math.ethz.ch
Subject: Re: [R-SIG-Finance] PerformanceAnalytics - small problem with Return.excess
A time series with only one element is not a 'series'.
In the case of excess returns, with only one return the excess return is the
return of your asset minus the return of the risk free or benchmark asset over
the same time period represented by your single number.
I'm not likely to spend time putting in a workaround, given that this is a
pretty rare/edge case, and I've got other higher priorities right now.
However, we would certainly welcome a patch if you wanted to take a look at the
code.
Regards,
- Brian
Giuseppe Milicia wrote:
> Guys,
>
> I've noticed a small problem in PerformanceAnalytics, Return.excess does not like timeseries with only 1 elements. Obviously this situation does not happen often, but getting around the issue is rather unelegant:
>
> Loading required package: PerformanceAnalytics
>
> Package PerformanceAnalytics (1.0.2.1) loaded.
> Econometric tools for performance and risk analysis.
> (c) 2004-2010 Peter Carl, Brian G. Peterson. License: GPL
> http://r-forge.r-project.org/projects/returnanalytics/
>
> data(managers)
>> Return.excess(managers[1,1,drop=FALSE], 0)
> Error in `colnames<-`(`*tmp*`, value = "HAM1 > 0") :
> attempt to set colnames on object with less than two dimensions
>
>
>> version
> _
> platform i386-pc-solaris2.10
> arch i386
> os solaris2.10
> system i386, solaris2.10
> status
> major 2
> minor 10.1
> year 2009
> month 12
> day 14
> svn rev 50720
> language R
> version.string R version 2.10.1 (2009-12-14)
>
> Cheers,
>
> //Giuseppe
--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock
---- MAKO ----
This email and any files transmitted with it are confide...{{dropped:14}}
More information about the R-SIG-Finance
mailing list