the 'drag' term, c0/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 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.
epoch
the string representation of the 'epoch', defaulting
to 'yr'.
Details
Suppose xi are n independent draws of a q-variate
normal random variable with mean mu and covariance matrix
Sigma. Let xbar be the (vector) sample mean, and
S be the sample covariance matrix (using Bessel's correction). Let
zeta(w) = (w'xbar - c0)/sqrt(w'Sw)
be the (sample) Sharpe ratio of the portfolio w, subject to
risk free rate c0.
Let w* be the solution to the portfolio optimization problem:
max {zeta(w) | 0 < w'Sw <= R^2},
with maximum value z* = zeta(w*).
Then
w* = R S^-1 xbar / sqrt(xbar' S^-1 xbar)
and
z* = sqrt(xbar' S^-1 xbar) - c0/R
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 and epoch are not given, the
converter from xts attempts to infer the observations per epoch,
assuming yearly epoch.
Other sropt: confint.sr,
dsropt, is.sropt,
pco_sropt, power.sropt_test,
reannualize, sropt_test,
sropt
Examples
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)
}
## Not run:
# 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)
}
## End(Not run)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(SharpeR)
Attaching package: 'SharpeR'
The following object is masked from 'package:base':
summary
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/SharpeR/as.sropt.Rd_%03d_medium.png", width=480, height=480)
> ### Name: as.sropt
> ### Title: Compute the Sharpe ratio of the Markowitz portfolio.
> ### Aliases: as.sropt as.sropt.default as.sropt.xts
> ### Keywords: univar
>
> ### ** Examples
>
> 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)
+ }
Loading required package: MASS
> ## Not run:
> ##D # using real data.
> ##D if (require(quantmod)) {
> ##D get.ret <- function(sym,...) {
> ##D OHLCV <- getSymbols(sym,auto.assign=FALSE,...)
> ##D lrets <- diff(log(OHLCV[,paste(c(sym,"Adjusted"),collapse=".",sep="")]))
> ##D # chomp first NA!
> ##D lrets[-1,]
> ##D }
> ##D get.rets <- function(syms,...) { some.rets <- do.call("cbind",lapply(syms,get.ret,...)) }
> ##D some.rets <- get.rets(c("IBM","AAPL","A","C","SPY","XOM"))
> ##D asro <- as.sropt(some.rets)
> ##D }
> ## End(Not run)
>
>
>
>
>
> dev.off()
null device
1
>