Hi Bernd,

It seems to me that the sharpe function uses the diff to calculate the first
differnce of the input which
is a cumalative return series. This is consistant. see sharpe
Basically you need the rate of returns ((priceFinal - Price
Initial)/priceInitial) which you used. In your case r = 0, so you are
calculating the simple signal to noise ratio (mean/std). It looks correct to
me.
The example given in the sharpe function does not seem to be correct though.

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

The input is a time series of closing prices. the simple log does not give a
rate of returns.
you need to use the log Difference of prices to get the returns. and then
divide by std of the return series.

I Hope this helps.

A.
On 2/19/07, Bernd Dittmann <herrdittmann@yahoo.co.uk> wrote:
>
> 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
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]

