[R] Calculating the Sharpe ratio
Bernd Dittmann
herrdittmann at yahoo.co.uk
Tue Feb 20 21:44:38 CET 2007
Hi Mark,
thanks for your email.
I used your formula for cumul. returns and plugged them into sharpe:
> mysharpe <- function(x){
+ return(sharpe(cret(x), r=0, scale=1))
+ }
whereby "cret" is my cumul. returns function as defined by:
> cret
function(x){
cumprod(diff(log(x))+1)-1
}
For the index series "Index" I obtain a sharpe ratio (r=0 and scale=1) of:
> mysharpe(Index)
[1] 0.8836429
Do you reckon this result and the method above are correct?
Many thanks in advance!
Bernd
Leeds, Mark (IED) schrieb:
> If the doc says to use cumulated and you didn't, then I supsect the call
> to shaprp in
> Tseries is not correct. Also, to get PercetnREturns, I hope you did
> diff(log(series))
> Where series is an object containing prices. It's not so clear
> Form your email.
>
> If you want to send in cumulative returns ( which
> You should do if the doc says to ) you just take the returns ( by doing
> above )
> and then , add 1 to each element, do a cumprod and then subtract 1 so
> something like :
>
> rtns<-diff(log(priceseries)
> oneplusrtns<-1+rtns
> cumprodrtns<-cumprod(oneplusreturns)
>
> cumrtns<-cumprodrtns-1.
>
> Then, the elements in cumrtns represent the cumulative reeturn upto that
> point.
>
> But, test it out with an easy example to make sure because I didn't.
>
>
>
>
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Bernd Dittmann
> Sent: Monday, February 19, 2007 8:39 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Calculating the Sharpe ratio
>
> 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 at 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.
> --------------------------------------------------------
>
> This is not an offer (or solicitation of an offer) to buy/sell the securities/instruments mentioned or an official confirmation. Morgan Stanley may deal as principal in or own or act as market maker for securities/instruments mentioned or may advise the issuers. This is not research and is not from MS Research but it may refer to a research analyst/research report. Unless indicated, these views are the author's and may differ from those of Morgan Stanley research or others in the Firm. We do not represent this is accurate or complete and we may not update this. Past performance is not indicative of future returns. For additional information, research reports and important disclosures, contact me or see https://secure.ms.com/servlet/cls. You should not use e-mail to request, authorize or effect the purchase or sale of any security or instrument, to send transfer instructions, or to effect any other transactions. We cannot guarantee that any such requests received via e-mail will be processed in a timely manner. This communication is solely for the addressee(s) and may contain confidential information. We do not waive confidentiality by mistransmission. Contact me if you do not wish to receive these communications. In the UK, this communication is directed in the UK to those persons who are market counterparties or intermediate customers (as defined in the UK Financial Services Authority's rules).
>
>
More information about the R-help
mailing list