Displaying 1 result from an estimated 1 matches for "mysharp".
Did you mean:
myshare
2007 Feb 19
2
Calculating the Sharpe ratio
...variation the "sharpe" function.
In both cases I used the risk free rate r=0 and scale=1 since I am using
annual data already.
My results:
METHOD 1: "sharpe":
> index <- log(Index)
> sharpe(index, scale=1)
[1] 0.9614212
METHOD 2: my own %-based formula:
> mysharp
function(x, r=0, scale=sqrt(250))
{
if (NCOL(x) > 1)
stop("x is not a vector or univariate time series")
if (any(is.na(x)))
stop("NAs in x")
if (NROW(x) ==1)
return(NA)
else{
return(scale * (mean(x) - r)/sd(x))
}
}
> mysharp(PercentReturns, scale=1)
[1] 0.982531
Both...