as.sr {SharpeR} | R Documentation |
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", 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 |
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 |
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 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.
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 shabbychef@gmail.com
References
Sharpe, William F. "Mutual fund performance." Journal of business (1966): 119-138. https://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. https://www.ssrn.com/paper=377260
See Also
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
# 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(xts)) {
data(stock_returns)
IBM <- stock_returns[,'IBM']
asr <- as.sr(IBM,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)
# 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)