Learn R Programming

SharpeR (version 0.1306)

as.sr: Compute the Sharpe ratio.

Description

Computes the Sharpe ratio of some observed returns.

Usage

as.sr(x,c0=0,ope=1,na.rm=FALSE,epoch="yr")

## S3 method for class 'default': as.sr(x, c0 = 0, ope = 1, na.rm = FALSE, epoch = "yr")

## S3 method for class 'data.frame': as.sr(x, c0 = 0, ope = 1, na.rm = FALSE, epoch = "yr")

## S3 method for class 'lm': as.sr(x, c0 = 0, ope = 1, na.rm = FALSE, epoch = "yr")

## S3 method for class 'xts': as.sr(x, c0 = 0, ope = 1, na.rm = FALSE, epoch = "yr")

Arguments

x
vector of returns, or object of class data.frame, xts, or lm.
c0
the 'risk-free' or 'disastrous' rate of return. this is assumed to be given in the same units as x, not in 'annualized' terms.
ope
the number of observations per 'epoch'. For convenience of interpretation, The Sharpe ratio is typically quoted in 'annualized' units for some epoch, that is, 'per square root epoch', though returns are observed at a frequency of ope
na.rm
logical. Should missing values be removed?
epoch
the string representation of the 'epoch', defaulting to 'yr'.

Value

  • a list containing the following components:
  • srthe annualized Sharpe ratio.
  • dfthe t-stat degrees of freedom.
  • c0the risk free term.
  • opethe annualization factor.
  • rescalthe rescaling factor.
  • epochthe string epoch.
  • cast to class sr.

Details

Suppose $x_i$ are $n$ independent returns of some asset. Let $\bar{x}$ be the sample mean, and $s$ be the sample standard deviation (using Bessel's correction). Let $c_0$ be the 'risk free rate'. Then $$z = \frac{\bar{x} - c_0}{s}$$ is the (sample) Sharpe ratio.

The units of $z$ are $\mbox{time}^{-1/2}$. Typically the Sharpe ratio is annualized by multiplying by $\sqrt{\mbox{ope}}$, where $\mbox{ope}$ is the number of observations per year (or whatever the target annualization epoch.)

Note that if ope is not given, the converter from xts attempts to infer the observations per year, without regard to the name of the epoch given.

References

Sharpe, William F. "Mutual fund performance." Journal of business (1966): 119-138. http://ideas.repec.org/a/ucp/jnlbus/v39y1965p119.html

Lo, Andrew W. "The statistics of Sharpe ratios." Financial Analysts Journal 58, no. 4 (2002): 36-52. http://ssrn.com/paper=377260

See Also

reannualize

sr-distribution functions, dsr, psr, qsr, rsr

Other sr: confint.sr, confint.sropt, dsr, is.sr, power.sr_test, print.sr, print.sropt, reannualize, reannualize.sr, reannualize.sropt, se, se.sr, sr, sr_equality_test, sr_test

Examples

Run this code
# Sharpe's 'model': just given a bunch of returns.
asr <- as.sr(rnorm(253*3),ope=253)
# or a matrix, with a name
my.returns <- matrix(rnorm(253*3),ncol=1)
colnames(my.returns) <- c("my strategy")
asr <- as.sr(my.returns)
# given an xts object:
if (require(quantmod)) {
  IBM <- getSymbols('IBM',auto.assign=FALSE)
  lrets <- diff(log(IBM[,"IBM.Adjusted"]))
  asr <- as.sr(lrets,na.rm=TRUE)
}
# on a linear model, find the 'Sharpe' of the residual term
nfac <- 5
nyr <- 10
ope <- 253
set.seed(as.integer(charToRaw("determinstic")))
Factors <- matrix(rnorm(ope*nyr*nfac,mean=0,sd=0.0125),ncol=nfac)
Betas <- exp(0.1 * rnorm(dim(Factors)[2]))
Returns <- (Factors %*% Betas) + rnorm(dim(Factors)[1],mean=0.0005,sd=0.012)
APT_mod <- lm(Returns ~ Factors)
asr <- as.sr(APT_mod,ope=ope)
# try again, but make the Returns independent of the Factors.
Returns <- rnorm(dim(Factors)[1],mean=0.0005,sd=0.012)
APT_mod <- lm(Returns ~ Factors)
asr <- as.sr(APT_mod,ope=ope)

Run the code above in your browser using DataLab