Learn R Programming

SharpeR (version 0.1306)

as.sropt: Compute the Sharpe ratio of the Markowitz portfolio.

Description

Computes the Sharpe ratio of the Markowitz portfolio of some observed returns.

Usage

as.sropt(X,drag=0,ope=1,epoch="yr")

## S3 method for class 'default': as.sropt(X, drag = 0, ope = 1, epoch = "yr")

## S3 method for class 'xts': as.sropt(X, drag = 0, ope = 1, epoch = "yr")

Arguments

X
matrix of returns, or xts object.
drag
the 'drag' term, $c_0/R$. defaults to 0. It is assumed that drag has been annualized, i.e. has been multiplied by $\sqrt{ope}$. This is in contrast to the c0 term given to sr<
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
epoch
the string representation of the 'epoch', defaulting to 'yr'.

Value

  • A list with containing the following components:
  • wthe optimal portfolio.
  • muthe estimated mean return vector.
  • Sigmathe estimated covariance matrix.
  • df1the number of assets.
  • df2the number of observed vectors.
  • T2the Hotelling $T^2$ statistic.
  • sroptthe optimal Sharpe statistic.
  • dragthe input drag term.
  • opethe input ope term.

Details

Suppose $x_i$ are $n$ independent draws of a $q$-variate normal random variable with mean $\mu$ and covariance matrix $\Sigma$. Let $\bar{x}$ be the (vector) sample mean, and $S$ be the sample covariance matrix (using Bessel's correction). Let $$\zeta(w) = \frac{w^{\top}\bar{x} - c_0}{\sqrt{w^{\top}S w}}$$ be the (sample) Sharpe ratio of the portfolio $w$, subject to risk free rate $c_0$.

Let $w_*$ be the solution to the portfolio optimization problem: $$\max_{w: 0 < w^{\top}S w \le R^2} \zeta(w),$$ with maximum value $z_* = \zeta\left(w_*\right)$. Then $$w_* = R \frac{S^{-1}\bar{x}}{\sqrt{\bar{x}^{\top}S^{-1}\bar{x}}}$$ and $$z_* = \sqrt{\bar{x}^{\top} S^{-1} \bar{x}} - \frac{c_0}{R}$$

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 and epoch are not given, the converter from xts attempts to infer the observations per epoch, assuming yearly epoch.

See Also

sr, sropt-distribution functions, dsropt, psropt, qsropt, rsropt

Other sropt: confint.sr, confint.sropt, dsropt, is.sropt, power.sropt_test, reannualize, reannualize.sr, reannualize.sropt, sropt, sropt_test

Examples

Run this code
nfac <- 5
nyr <- 10
ope <- 253
# simulations with no covariance structure.
# under the null:
set.seed(as.integer(charToRaw("be determinstic")))
Returns <- matrix(rnorm(ope*nyr*nfac,mean=0,sd=0.0125),ncol=nfac)
asro <- as.sropt(Returns,drag=0,ope=ope)
# under the alternative:
Returns <- matrix(rnorm(ope*nyr*nfac,mean=0.0005,sd=0.0125),ncol=nfac)
asro <- as.sropt(Returns,drag=0,ope=ope)
# generating correlated multivariate normal data in a more sane way
if (require(MASS)) {
  nstok <- 10
  nfac <- 3
  nyr <- 10
  ope <- 253
  X.like <- 0.01 * matrix(rnorm(500*nfac),ncol=nfac) %*%
    matrix(runif(nfac*nstok),ncol=nstok)
  Sigma <- cov(X.like) + diag(0.003,nstok)
  # under the null:
  Returns <- mvrnorm(ceiling(ope*nyr),mu=matrix(0,ncol=nstok),Sigma=Sigma)
  asro <- as.sropt(Returns,ope=ope)
  # under the alternative
  Returns <- mvrnorm(ceiling(ope*nyr),mu=matrix(0.001,ncol=nstok),Sigma=Sigma)
  asro <- as.sropt(Returns,ope=ope)
}
# using real data.
if (require(quantmod)) {
  get.ret <- function(sym,...) {
    OHLCV <- getSymbols(sym,auto.assign=FALSE,...)
    lrets <- diff(log(OHLCV[,paste(c(sym,"Adjusted"),collapse=".",sep="")]))
    # chomp first NA!
    lrets[-1,]
  }
  get.rets <- function(syms,...) { some.rets <- do.call("cbind",lapply(syms,get.ret,...)) }
  some.rets <- get.rets(c("IBM","AAPL","A","C","SPY","XOM"))
  asro <- as.sropt(some.rets)
}

Run the code above in your browser using DataLab