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