[R] Calculating the Sharpe ratio

Bernd Dittmann herrdittmann at yahoo.co.uk
Mon Feb 19 14:39:07 CET 2007


Hi useRs,

I am trying to calculate the Sharpe ratio with "sharpe" of the library 
"tseries".

The documentation requires the univariate time series to be a 
portfolio's cumulated returns. In this case, the example given

data(EuStockMarkets)
dax <- log(EuStockMarkets[,"FTSE"])

is however not the cumulated returns but rather the daily returns of the 
FTSE stock index.

Is this way of calculating the Sharpe ratio correct?

Here are my own data:

year    Index    PercentReturns
1985    117    0.091
1986    129.9    0.11
1987    149.9    0.154
1988    184.8    0.233
1989    223.1    0.208
1990    223.2    0
1991    220.5    -0.012
1992    208.1    -0.056
1993    202.1    -0.029
1994    203.1    0.005
1995    199.6    -0.017
1996    208.6    0.045
1997    221.7    0.063
1998    233.7    0.054
1999    250.5    0.072
2000    275.1    0.098
2001    298.6    0.085
2002    350.6    0.174
2003    429.1    0.224
2004    507.6    0.183
2005    536.6    0.057
2006    581.3    0.083


I calculated the Sharpe ratio in two different ways:
(1) using natural logs as approximation of % returns, using "sharpe" of 
"tseries".
(2) using the % returns using a 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 Sharp ratios differ only slightly since logs approximate percentage 
changes (returns).


Are both methods correct, esp. since I am NOT using cumulated returns as 
the manual says?

If cumulated returns were supposed to be used, could I cumulate the 
%-returns with "cumsum(PercentReturns)"?

Many thanks in advance!

Bernd



More information about the R-help mailing list