as.sr: Compute the Sharpe ratio.

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

Computes the Sharpe ratio of some observed returns.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
as.sr(x, c0 = 0, ope = 1, na.rm = FALSE, epoch = "yr",
  higher_order = FALSE)

## Default S3 method:
as.sr(x, c0 = 0, ope = 1, na.rm = FALSE, epoch = "yr",
  higher_order = FALSE)

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

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

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

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

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

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 per epoch. The default value is 1, meaning the code will not attempt to guess what the observation frequency is, and no annualization adjustments will be made.

na.rm

logical. Should missing values be removed?

epoch

the string representation of the 'epoch', defaulting to 'yr'.

higher_order

a Boolean. If true, we compute cumulants of the returns to leverage higher order accuracy formulae when possible.

Details

Suppose xi are n independent returns of some asset. Let xbar be the sample mean, and s be the sample standard deviation (using Bessel's correction). Let c0 be the 'risk free rate'. Then

z = (xbar - c0)/s

is the (sample) Sharpe ratio.

The units of z are per root time. Typically the Sharpe ratio is annualized by multiplying by sqrt(ope), where 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.

Value

a list containing the following components:

sr

the annualized Sharpe ratio.

df

the t-stat degrees of freedom.

c0

the risk free term.

ope

the annualization factor.

rescal

the rescaling factor.

epoch

the string epoch.

cast to class sr.

Author(s)

Steven E. Pav [email protected]

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, dsr, is.sr, plambdap, power.sr_test, predint, print.sr, reannualize, se, sr_equality_test, sr_test, sr_unpaired_test, sr_vcov, sr, summary.sr

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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:
## Not run: 
if (require(quantmod)) {
  IBM <- getSymbols('IBM',auto.assign=FALSE)
  lrets <- diff(log(IBM[,"IBM.Adjusted"]))
  asr <- as.sr(lrets,na.rm=TRUE)
}

## End(Not run)
# 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)

# compute the Sharpe of a bunch of strategies:
my.returns <- matrix(rnorm(253*3*4),ncol=4)
asr <- as.sr(my.returns)  # without sensible colnames?
colnames(my.returns) <- c("strat a","strat b","strat c","strat d")
asr <- as.sr(my.returns)
  

shabbychef/SharpeR documentation built on May 29, 2019, 8:05 p.m.